0

我目前在通过意图传递 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);
}

日志猫:

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)
4

0 回答 0