我有一个活动和片段的应用程序,我使用此
在片段之间导航 fragmentManager.beginTransaction()
.addToBackStack(null)
.replace(R.id.mainContainer, postesFragment)
.commitAllowingStateLoss();
我有一个带有子片段的片段(使用viewPager),当我添加它的确定时,然后使用
弹出它fragmentManager.popBackStack()
这里没有问题,但是当我向上面的Backstack添加另一个片段时,我弹出它会导致应用程序因此异常而崩溃
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)
我发现了这个问题NullPointerException related to FragmentManager.popBackStack. How to resolve?
并且问题不会始终发生,我在Galaxy E5(e53g)面对它
请任何帮助..
答案 0 :(得分:0)
尝试这个
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.addToBackStack(null);
transaction.replace(R.id.main_container, fragment);
transaction.commit();
如果它显示相同的问题,则不要使用
fragmentManager.popBackStack()
答案 1 :(得分:0)
我刚解决了。
仅使用supportFragmentManager
代替FragmentManager
和support.v4.fragment
代替app.fragment
。
答案 2 :(得分:0)
请在调用setSharedElementReturnTransition和setExitTransition方法时提供片段的引用。例如,
frg.setSharedElementReturnTransition(TransitionInflater.from(
getActivity()).inflateTransition(R.transition.profile_image_transform));
frg.setExitTransition(TransitionInflater.from(
getActivity()).inflateTransition(R.transition.profile_image_transform));