所以我有一个浴室类,通过另一个活动中的按钮实现Parcelable和onClick:
Intent i = new Intent(getApplicationContext(), BathroomView1.class);
Bundle b = new Bundle();
b.putParcelable("myObject", this);
i.putExtras(b);
startActivity(i);
和我在onCreate里面的我的BathroomView1,我有:
loc = (Bathroom)this.getIntent().getExtras().getParcelable("myObject");
但我继续在该行上获取空指针异常。继承我的logcat:
11-05 22:16:51.399: E/AndroidRuntime(19991): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.poopify/com.example.poopify.BathroomView1}: java.lang.NullPointerException
11-05 22:16:51.399: E/AndroidRuntime(19991): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
11-05 22:16:51.399: E/AndroidRuntime(19991): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
11-05 22:16:51.399: E/AndroidRuntime(19991): at android.app.ActivityThread.access$700(ActivityThread.java:143)
11-05 22:16:51.399: E/AndroidRuntime(19991): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
11-05 22:16:51.399: E/AndroidRuntime(19991): at android.os.Handler.dispatchMessage(Handler.java:99)
11-05 22:16:51.399: E/AndroidRuntime(19991): at android.os.Looper.loop(Looper.java:137)
11-05 22:16:51.399: E/AndroidRuntime(19991): at android.app.ActivityThread.main(ActivityThread.java:4950)
11-05 22:16:51.399: E/AndroidRuntime(19991): at java.lang.reflect.Method.invokeNative(Native Method)
11-05 22:16:51.399: E/AndroidRuntime(19991): at java.lang.reflect.Method.invoke(Method.java:511)
11-05 22:16:51.399: E/AndroidRuntime(19991): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
11-05 22:16:51.399: E/AndroidRuntime(19991): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
11-05 22:16:51.399: E/AndroidRuntime(19991): at dalvik.system.NativeStart.main(Native Method)
11-05 22:16:51.399: E/AndroidRuntime(19991): Caused by: java.lang.NullPointerException
11-05 22:16:51.399: E/AndroidRuntime(19991): at com.example.poopify.BathroomView1.onCreate(BathroomView1.java:42)
11-05 22:16:51.399: E/AndroidRuntime(19991): at android.app.Activity.performCreate(Activity.java:5179)
11-05 22:16:51.399: E/AndroidRuntime(19991): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
11-05 22:16:51.399: E/AndroidRuntime(19991): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)