我有一个带有几个列表片段的 mainActivity,例如 A、B、C 和 D。这些片段在主要活动中的导航是 A->B->C->D。
从片段 D 开始新的 detailsActivity。当我按下返回按钮时,在 detailsActivity 上,我应该返回带有所选片段的 mainActivity。
这在除 android 4.3 之外的所有版本的 android 中都可以正常工作。我得到关注 NullPointerException。我观察到的差异是,在 android 4.3 中,在 mainActivity 上调用了后退导航 onCreate 方法,这在以前的 Android 版本中没有发生。我找不到解决方法,请帮助!
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.main/com.app.main.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.widget.ArrayAdapter.getCount(ArrayAdapter.java:330)
at android.widget.ListView.setAdapter(ListView.java:463)
at android.support.v4.app.ListFragment.setListAdapter(ListFragment.java:182)
at android.support.v4.app.ListFragment.ensureList(ListFragment.java:365)
at android.support.v4.app.ListFragment.onViewCreated(ListFragment.java:145)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:941)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1086)
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1877)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:552)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
at android.app.Activity.performStart(Activity.java:5143)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)