i have an application with one activity and fragments,i am navigating between fragment using this
fragmentManager.beginTransaction()
.addToBackStack(null)
.replace(R.id.mainContainer, postesFragment)
.commitAllowingStateLoss();
i have a fragment with sub-fragments(using viewPager), when i add it its ok, and pop it using
fragmentManager.popBackStack()
here is no problem, but when i add another fragment to the backstack above this, and i pop it the application crashes due to this exception
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.util.ArrayList.size()' on a null object reference
at android.app.BackStackRecord.setBackNameOverrides(BackStackRecord.java:1683)
at android.app.BackStackRecord.remapSharedElements(BackStackRecord.java:1092)
at android.app.BackStackRecord.configureTransitions(BackStackRecord.java:1299)
at android.app.BackStackRecord.beginTransition(BackStackRecord.java:1011)
at android.app.BackStackRecord.popFromBackStack(BackStackRecord.java:1566)
at android.app.FragmentManagerImpl.popBackStackState(FragmentManager.java:1519)
at android.app.FragmentManagerImpl$2.run(FragmentManager.java:495)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
at android.app.FragmentManagerImpl$1.run(FragmentManager.java:452)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6856)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
i find this question NullPointerException related to FragmentManager.popBackStack. How to resolve?
and the problem not occurs always, i faced it on Galaxy E5 (e53g)
please any help ..
I have just solved it.
Just using
supportFragmentManager
instead ofFragmentManager
andsupport.v4.fragment
instead ofapp.fragment
.