0

In my app I have the MainActivity containing two fragments that are tabbed. Somehow I get an exception that is evolving from the MainActivity's onDestroy that is eventually calling fragment's onCreateView.

I am aware that in the fragment's lifecycle the onCreateView should be called after onDestroyView but not after onDestroy.

I actually don't know how to reproduce this issue but I attached the stack trace:

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)

In the end, this onCreatView is creating a null pointer exception that is evolved from my code, but I don't want to patch it with (if mMember != null) or something, I want to understand what happens and why this flow happens this way.

Thanks.

0 Answers0