0

在我的应用程序中,我的 MainActivity 包含两个选项卡式片段。不知何故,我得到了一个从 MainActivity 的 onDestroy 演变而来的异常,该异常最终调用了 Fragment 的 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)或其他东西来修补它,我想了解发生了什么以及为什么会发生这种流程这边走。

谢谢。

4

0 回答 0