0
java.lang.NullPointerException: Attempt to read from field 'int android.support.v4.app.Fragment.mContainerId' on a null object reference
at android.support.v4.app.FragmentTransition.addToFirstInLastOut(FragmentTransition.java:1017)
at android.support.v4.app.FragmentTransition.calculatePopFragments(FragmentTransition.java:996)
at android.support.v4.app.FragmentTransition.startTransitions(FragmentTransition.java:93)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2146)
at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2013)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:710)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6126)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

I have one activity a navigation drawer with fragments handling the views, my transitions and such work fine until i start rotating then i get that. Note: The rotation works fine upon first visit but when go away then return to the fragment > rotate > select other fragment in navi drawer it crashes. please advice would be great!

here is some more code:

Fragment currentFrag = getSupportFragmentManager().findFragmentById(R.id.newsfeedContainer);
if (currentFrag instanceof NewsFeedFragment) {
  result.closeDrawer();
} else {
  if (newsFeedFragment != null) {
    getSupportFragmentManager().popBackStack(null, POP_BACK_STACK_INCLUSIVE);
    transaction.show(newsFeedFragment);
    transaction.addToBackStack("newsfeed");
    transaction.commit();
  }
}

result.closeDrawer();

} this is part my navigation drawer.. when this item is selected it works.. but when I open another fragment and come back to the previous fragment AND ROTATE it gives a nullpointer

user3875913
  • 245
  • 2
  • 11
  • I understand what a nullpointer is and how to fix them.. what i dont get here is that i do not get a nullpointer until extensive rotations – user3875913 May 09 '17 at 14:16
  • post the code bruh! – Kaushal28 May 09 '17 at 14:26
  • I'm not sure where to start as the fragments are complex but here is a start let me know if you all need more – user3875913 May 09 '17 at 14:37
  • It seems your'e trying to read mContainerId from a NULL fragment. Why don't you put the code of that part? – Gustavo Conde May 09 '17 at 14:52
  • Put into fragment/activity lifecycle calls like onStart/onStop/onAttach/... logcat output to see how the lifetime of your fragments/activities is affected by rotation, depending on your project setup, IIRC, the activity is probably destroyed + created new one, while fragments may be just attached/detached (an survive rotation), or even those may get destroyed + created from Bundle state. Verify you don't leak some instance by keeping it around, and work always with the newly created ones. BTW, your code is calling `result.closeDrawer();` twice for `NewsFeedFragment` type (probably not a prob)? – Ped7g May 09 '17 at 15:27
  • Thank you @Ped7g let me try doing that – user3875913 May 09 '17 at 17:03

0 Answers0