我正在获取空指针异常错误,同时在意图上传递ID。我在代码上标记了错误似乎发生的地方。
希望有人能看到我出错的地方。
这是我的代码,它将选定的ID(从列表视图)添加到意图:
public void onListItemClick(ListView list, View v, int list_posistion, long item_id)
{
long idToPass = item_id;
Intent setName = new Intent("com.example.flybase2.addAppointment");
setName.putExtra("passedID", idToPass);
startActivity(setName);
}
继承意图打开的类,显示包含传递的ID的包:
//ERROR: Error occuring on this bundle when setting the ID variable.
Bundle passedID = getIntent().getExtras();
if (passedID != null) {
ID = passedID.getLong("passedID");
DBHandlerApp NameAppointPass = new DBHandlerApp(this, null, null);
NameAppointPass.open();
String nameReturned = NameAppointPass.getName(ID);
setName.setText(nameReturned);
}
logcat的:
01-21 19:14:16.808: E/AndroidRuntime(274): FATAL EXCEPTION: main
01-21 19:14:16.808: E/AndroidRuntime(274): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.flybase2/com.example.flybase2.addAppointment}: java.lang.NullPointerException
01-21 19:14:16.808: E/AndroidRuntime(274): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-21 19:14:16.808: E/AndroidRuntime(274): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-21 19:14:16.808: E/AndroidRuntime(274): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-21 19:14:16.808: E/AndroidRuntime(274): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-21 19:14:16.808: E/AndroidRuntime(274): at android.os.Handler.dispatchMessage(Handler.java:99)
01-21 19:14:16.808: E/AndroidRuntime(274): at android.os.Looper.loop(Looper.java:123)
01-21 19:14:16.808: E/AndroidRuntime(274): at android.app.ActivityThread.main(ActivityThread.java:4627)
01-21 19:14:16.808: E/AndroidRuntime(274): at java.lang.reflect.Method.invokeNative(Native Method)
01-21 19:14:16.808: E/AndroidRuntime(274): at java.lang.reflect.Method.invoke(Method.java:521)
01-21 19:14:16.808: E/AndroidRuntime(274): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-21 19:14:16.808: E/AndroidRuntime(274): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-21 19:14:16.808: E/AndroidRuntime(274): at dalvik.system.NativeStart.main(Native Method)
01-21 19:14:16.808: E/AndroidRuntime(274): Caused by: java.lang.NullPointerException
01-21 19:14:16.808: E/AndroidRuntime(274): at com.example.flybase2.addAppointment.onCreate(addAppointment.java:57)
01-21 19:14:16.808: E/AndroidRuntime(274): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-21 19:14:16.808: E/AndroidRuntime(274): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)