NullpointerException on Backstack

旧城冷巷雨未停 提交于 2019-12-13 00:16:16

问题


I use API Level 16, in i try to replace some Fragment below some Tab where already is some Fragment. I cant really find a reason why, but sometimes i get an Exception like this:

E/AndroidRuntime(27395): java.lang.NullPointerException
E/AndroidRuntime(27395):    at android.app.BackStackRecord.run(BackStackRecord.java:604)
E/AndroidRuntime(27395):    at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1399)
E/AndroidRuntime(27395):    at android.app.FragmentManagerImpl$1.run(FragmentManager.java:426)
E/AndroidRuntime(27395):    at android.os.Handler.handleCallback(Handler.java:615)
E/AndroidRuntime(27395):    at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime(27395):    at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(27395):    at android.app.ActivityThread.main(ActivityThread.java:4921)
E/AndroidRuntime(27395):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(27395):    at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(27395):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
E/AndroidRuntime(27395):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
E/AndroidRuntime(27395):    at dalvik.system.NativeStart.main(Native Method)

I do not add an null Fragment and code running there is simple:

            final Fragment newFragment = Fragment.instantiate(anContext, clazz.getName(), arguments);
            final FragmentTransaction transaction = manager.beginTransaction();
            transaction.disallowAddToBackStack();
            transaction.replace(R.id.fragment_content_center, newFragment);
            transaction.commit();

If you like, have a look on Grepcode, as there the Exception happens: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.1.2_r1/android/app/BackStackRecord.java#604

Im not using any Animations there.


回答1:


The Problem was something different,

i was using in each Transaction an Fragment TAG when doing the replace call. On the upper code i didnt. That was causing this NullPointerException.

Look like you cant mix transactions, Documentation is not clear about that.

thanx, Kitesurfer



来源:https://stackoverflow.com/questions/15260059/nullpointerexception-on-backstack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!