02-07 16:26:30.621: E/AndroidRuntime(19951): java.lang.NullPointerException
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.support.v4.app.Fragment.instantiate(Fragment.java:399)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.support.v4.app.FragmentState.instantiate(Fragment.java:97)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.support.v4.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:1790)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.support.v4.app.Fragment.performCreate(Fragment.java:1489)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:893)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:472)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:163)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.support.v4.view.ViewPager.populate(ViewPager.java:1128)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.support.v4.view.ViewPager.populate(ViewPager.java:975)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1505)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.view.View.measure(View.java:15575)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.view.View.measure(View.java:15575)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5107)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.view.View.measure(View.java:15575)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5107)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1396)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.view.View.measure(View.java:15575)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5107)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
02-07 16:26:30.621: E/AndroidRuntime(19951): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2423)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.view.View.measure(View.java:15575)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2033)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1251)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1427)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1144)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4730)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.view.Choreographer.doFrame(Choreographer.java:525)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.os.Handler.handleCallback(Handler.java:615)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.os.Handler.dispatchMessage(Handler.java:92)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.os.Looper.loop(Looper.java:137)
02-07 16:26:30.621: E/AndroidRuntime(19951): at android.app.ActivityThread.main(ActivityThread.java:4947)
02-07 16:26:30.621: E/AndroidRuntime(19951): at java.lang.reflect.Method.invokeNative(Native Method)
02-07 16:26:30.621: E/AndroidRuntime(19951): at java.lang.reflect.Method.invoke(Method.java:511)
02-07 16:26:30.621: E/AndroidRuntime(19951): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
02-07 16:26:30.621: E/AndroidRuntime(19951): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
02-07 16:26:30.621: E/AndroidRuntime(19951): at dalvik.system.NativeStart.main(Native Method)
算是解決了吧,在Fragment被detached的時候去重置ChildFragmentManager
這樣就不會再報空
@Override
public void onDetach() {
super.onDetach();
Field childFragmentManager;
try {
childFragmentManager = Fragment.class
.getDeclaredField("mChildFragmentManager");
childFragmentManager.setAccessible(true);
childFragmentManager.set(this, null);
} catch (NoSuchFieldException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}