AppCompatActivity onDestroy调用Fragment的onCreateView?

时间:2017-03-28 10:20:33

标签: android android-activity android-lifecycle activity-lifecycle fragment-lifecycle

在我的应用程序中,我的MainActivity包含两个标签的片段。 不知何故,我得到了一个异常,它是从MainActivity的onDestroy发展而来的,最终调用片段的onCreateView。

我知道在片段的生命周期中,onCreateView应该在onDestroyView之后调用,而不是在onDestroy之后调用。

我实际上不知道如何重现这个问题,但我附上了堆栈跟踪:

Fatal Exception: java.lang.RuntimeException: Unable to destroy activity {com.myapp.myapp/com.myapp.activities.MainActivity}: java.lang.NullPointerException: Attempt to read from field 'com.myapp.model.Team com.myapp.model.User.team' on a null object reference
       at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4203)
       at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4221)
       at android.app.ActivityThread.-wrap6(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1538)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:154)
       at android.app.ActivityThread.main(ActivityThread.java:6119)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) Caused by java.lang.NullPointerException: Attempt to read from field 'com.myapp.model.Team com.myapp.model.User.team' on a null object reference
       at com.myapp.adapters.ActivitiesListAdapter.updateActivities(ActivitiesListAdapter.java:130)
       at com.myapp.adapters.ActivitiesListAdapter.<init>(ActivitiesListAdapter.java:125)
       at com.myapp.fragements.FeedFragment.onCreateView(FeedFragment.java:110)
       at android.support.v4.app.Fragment.performCreateView(Fragment.java:2189)
       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1299)
       at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)
       at android.support.v4.app.FragmentManagerImpl.dispatchReallyStop(FragmentManager.java:2915)
       at android.support.v4.app.FragmentController.dispatchReallyStop(FragmentController.java:249)
       at android.support.v4.app.FragmentActivity.onReallyStop(FragmentActivity.java:816)
       at android.support.v4.app.FragmentActivity.doReallyStop(FragmentActivity.java:795)
       at android.support.v4.app.FragmentActivity.onDestroy(FragmentActivity.java:388)
       at android.support.v7.app.AppCompatActivity.onDestroy(AppCompatActivity.java:209)
       at com.myapp.activities.MainActivity.onDestroy(MainActivity.java:772)
       at android.app.Activity.performDestroy(Activity.java:6881)
       at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1153)
       at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4190)
       at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4221)
       at android.app.ActivityThread.-wrap6(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1538)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:154)
       at android.app.ActivityThread.main(ActivityThread.java:6119)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

最后,这个onCreatView正在创建一个从我的代码演变而来的空指针异常,但我不想用它修补它(如果mMember!= null)或其他东西,我想了解发生了什么以及为什么这种流程就是这样发生的。

感谢。

0 个答案:

没有答案