我現在面臨很奇怪的問題,這個堆棧跟蹤:FragmentManager - IllegalStateException異常 - 無主機
Fatal Exception: java.lang.IllegalStateException No host
android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1194)
android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1189)
android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated (FragmentManager.java:2001)
android.support.v4.app.Fragment.performActivityCreated (Fragment.java:1976)
android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1051)
android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1207)
android.support.v4.app.BackStackRecord.run (BackStackRecord.java:738)
android.support.v4.app.FragmentManagerImpl.execPendingActions (FragmentManager.java:1572)
android.support.v4.app.FragmentManagerImpl$1.run (FragmentManager.java:493)
android.os.Handler.handleCallback (Handler.java:733)
android.os.Handler.dispatchMessage (Handler.java:95)
android.os.Looper.loop (Looper.java:146)
android.app.ActivityThread.main (ActivityThread.java:5593)
java.lang.reflect.Method.invokeNative (Method.java)
java.lang.reflect.Method.invoke (Method.java:515)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1283)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1099)
dalvik.system.NativeStart.main (NativeStart.java)
我跟蹤4個OCCURENCES此崩潰多的Android版本(4.1.2,4.2.2,6.0)的。我使用了很多Fragments
,這意味着我無法弄清楚拋出異常的位置。
代碼FragmentManager
:
void moveToState(int newState, int transit, int transitStyle, boolean always) {
if (mHost == null && newState != Fragment.INITIALIZING) {
throw new IllegalStateException("No host");
}
...
}
在我看來,出現這種情況時,有屬於Fragment
沒有主機Activity
。我調用了setRetainInstance()`,但我根本不使用它。
感謝您的每一個建議。
嗨,大家好,你有任何解決方案,這個問題呢? –