当我在模拟器上单击 CheckData 按钮时,它显示一个
> error: android.content.ActivityNotFoundException: Unable to find
> explicit activity class {app.login/app.login.DatabaseSample}; have you
> declared this activity in your AndroidManifest.xml?
但我已在 android mnaifest.xml 中声明为
package="app.login"<application
android:icon="@drawable/ic_launcher" android:label="@string/app_name" >
<activity
android:label="@string/app_name" android:name=".LoginappActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SaveData"> </activity>
<activity android:name=".CheckData"></activity>
<activity android:name=".DatabaseSample"> </activity>
</application>
这是我的 CheckData.java 文件
public class CheckData extends ListActivity {
TextView selection;
public int idToModify;
DataManipulator dm;
List<String[]> names1 =null ;
String[] stg1;
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.check);
dm = new DataManipulator(this);
names1 = dm.selectAll();
stg1=new String[names1.size()];
String stg;
for (String[] name : names1) {stg = name[1];
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
this,android.R.layout.simple_list_item_1,stg1);
this.setListAdapter(adapter);
selection=(TextView)findViewById(R.id.selection);
}
public void onListItemClick(ListView parent, View v, int position, long id) {
selection.setText(stg1[position]);
}
}
Logcat 是
05-10 12:42:03.292: E/AndroidRuntime(606): FATAL EXCEPTION: main
05-10 12:42:03.292: E/AndroidRuntime(606): java.lang.RuntimeException: Unable to start activity ComponentInfo{app.login/app.login.DatabaseSample}: java.lang.NullPointerException
05-10 12:42:03.292: E/AndroidRuntime(606): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
05-10 12:42:03.292: E/AndroidRuntime(606): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
05-10 12:42:03.292: E/AndroidRuntime(606): at android.app.ActivityThread.access$600(ActivityThread.java:123)
05-10 12:42:03.292: E/AndroidRuntime(606): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
05-10 12:42:03.292: E/AndroidRuntime(606): at android.os.Handler.dispatchMessage(Handler.java:99)
05-10 12:42:03.292: E/AndroidRuntime(606): at android.os.Looper.loop(Looper.java:137)
05-10 12:42:03.292: E/AndroidRuntime(606): at android.app.ActivityThread.main(ActivityThread.java:4424)
05-10 12:42:03.292: E/AndroidRuntime(606): at java.lang.reflect.Method.invokeNative(Native Method)
05-10 12:42:03.292: E/AndroidRuntime(606): at java.lang.reflect.Method.invoke(Method.java:511)
05-10 12:42:03.292: E/AndroidRuntime(606): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-10 12:42:03.292: E/AndroidRuntime(606): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-10 12:42:03.292: E/AndroidRuntime(606): at dalvik.system.NativeStart.main(Native Method)
05-10 12:42:03.292: E/AndroidRuntime(606): Caused by: java.lang.NullPointerException
05-10 12:42:03.292: E/AndroidRuntime(606): at app.login.DatabaseSample.onCreate(DatabaseSample.java:16)
05-10 12:42:03.292: E/AndroidRuntime(606): at android.app.Activity.performCreate(Activity.java:4465)
05-10 12:42:03.292: E/AndroidRuntime(606): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-10 12:42:03.292: E/AndroidRuntime(606): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
05-10 12:42:03.292: E/AndroidRuntime(606): ... 11 more
在模拟器上显示不幸的是 loginapp 已停止
这是我的 DatabaseSample.java 文件
public class DatabaseSample extends Activity implements OnClickListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
View button1Click = findViewById(R.id.Button01add);
button1Click.setOnClickListener(this);
View button2Click = findViewById(R.id.Button01home);
button2Click.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.Button01add:
Intent i = new Intent(this, SaveData.class);
startActivity(i);
break;
case R.id.Button01home:
Intent i1 = new Intent(this, CheckData.class);
startActivity(i1);
break;
}
}
}