書いてみたら
Car myCarObject=getCar();
Intent details = new Intent(Start.this, DetailsCar.class);
details.putExtra("Car", myCarObject);
startActivity(details);
Eclipse の行に「The Method Put Extra is Ambiguous for the type Intent」というコンパイル エラーが表示される
details.putExtra("Car", myCarObject);
コードを使用する場合
Car myCarObject=getCar();
ArrayList<Car> parcelableExtra = new ArrayList<Car>();
parcelableExtra.add(myCarObject);
Intent details = new Intent(Start.this, DetailsCar.class);
details.putExtra("Car", parcelableExtra);
startActivity(dettagli);
そして、宛先のインテントでこのコードを使用してエクストラをロードしようとします
ArrayList<Car> parcelableExtra = new ArrayList<Car>();
parcelableExtra = (ArrayList<Car>) getIntent().getExtras().getParcelable("Car");
Car c=parcelableExtra.get(0);
この警告が表示されます
12-14 05:30:07.669: W/Bundle(19823): Key Car expected Parcelable but value was a java.util.ArrayList. The default value <null> was returned.
12-14 05:30:07.679: W/Bundle(19823): Attempt to cast generated internal exception:
12-14 05:30:07.679: W/Bundle(19823): java.lang.ClassCastException: java.util.ArrayList
12-14 05:30:07.679: W/Bundle(19823): at android.os.Bundle.getParcelable(Bundle.java:1106)
12-14 05:30:07.679: W/Bundle(19823): at my.app.com.DetailsCar.onCreate(DetailsCar.java:43)
12-14 05:30:07.679: W/Bundle(19823): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-14 05:30:07.679: W/Bundle(19823): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
12-14 05:30:07.679: W/Bundle(19823): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
12-14 05:30:07.679: W/Bundle(19823): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-14 05:30:07.679: W/Bundle(19823): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
12-14 05:30:07.679: W/Bundle(19823): at android.os.Handler.dispatchMessage(Handler.java:99)
12-14 05:30:07.679: W/Bundle(19823): at android.os.Looper.loop(Looper.java:130)
12-14 05:30:07.679: W/Bundle(19823): at android.app.ActivityThread.main(ActivityThread.java:3687)
12-14 05:30:07.679: W/Bundle(19823): at java.lang.reflect.Method.invokeNative(Native Method)
12-14 05:30:07.679: W/Bundle(19823): at java.lang.reflect.Method.invoke(Method.java:507)
12-14 05:30:07.679: W/Bundle(19823): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
12-14 05:30:07.679: W/Bundle(19823): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
12-14 05:30:07.679: W/Bundle(19823): at dalvik.system.NativeStart.main(Native Method)
12-14 05:30:07.679: W/dalvikvm(19823): threadid=1: thread exiting with uncaught exception (group=0x40018578)
Null Point Exception でアプリがクラッシュする
My Car オブジェクトはパーセル可能です
それで....何が悪いのですか?