この方法で、ArrayListを新しいアクティビティに渡そうとしています。
Intent it = new Intent(activity, DownloadSelectionActivity.class);
it.putExtra("anos", yearList);
activity.startActivity(new Intent(activity, DownloadSelectionActivity.class));
私のyearListはOKで、Logにすべての値が表示されますが、以下のコードを使用して取得しようとすると、NullPointerExcepetionが返されます。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_downloadselection);
ArrayList<Integer> anosLista = (ArrayList<Integer>) getIntent().getSerializableExtra("anos");
for (Integer anos : anosLista) {
Log.d(Constants.DOWNLOAD_SELECTED_ACTIVITY, String.valueOf(anos));
}
例外:
03-25 20:11:18.144: E/AndroidRuntime(7899): FATAL EXCEPTION: main
03-25 20:11:18.144: E/AndroidRuntime(7899): java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.facilit.target.app.android/br.com.facilit.target.app.android.DownloadSelectionActivity}: java.lang.NullPointerException
03-25 20:11:18.144: E/AndroidRuntime(7899): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
03-25 20:11:18.144: E/AndroidRuntime(7899): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-25 20:11:18.144: E/AndroidRuntime(7899): at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-25 20:11:18.144: E/AndroidRuntime(7899): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-25 20:11:18.144: E/AndroidRuntime(7899): at android.os.Handler.dispatchMessage(Handler.java:99)
03-25 20:11:18.144: E/AndroidRuntime(7899): at android.os.Looper.loop(Looper.java:137)
03-25 20:11:18.144: E/AndroidRuntime(7899): at android.app.ActivityThread.main(ActivityThread.java:5041)
03-25 20:11:18.144: E/AndroidRuntime(7899): at java.lang.reflect.Method.invokeNative(Native Method)
03-25 20:11:18.144: E/AndroidRuntime(7899): at java.lang.reflect.Method.invoke(Method.java:511)
03-25 20:11:18.144: E/AndroidRuntime(7899): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-25 20:11:18.144: E/AndroidRuntime(7899): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-25 20:11:18.144: E/AndroidRuntime(7899): at dalvik.system.NativeStart.main(Native Method)
03-25 20:11:18.144: E/AndroidRuntime(7899): Caused by: java.lang.NullPointerException
03-25 20:11:18.144: E/AndroidRuntime(7899): at br.com.facilit.target.app.android.DownloadSelectionActivity.onCreate(DownloadSelectionActivity.java:26)
03-25 20:11:18.144: E/AndroidRuntime(7899): at android.app.Activity.performCreate(Activity.java:5104)
03-25 20:11:18.144: E/AndroidRuntime(7899): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
03-25 20:11:18.144: E/AndroidRuntime(7899): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
03-25 20:11:18.144: E/AndroidRuntime(7899): ... 11 more