TongTongBlog 2015-02-07 10:21 采纳率: 100%
浏览 4905
已采纳

Viewpager中的fragment内嵌fragment,滑动报错

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)

  • 写回答

3条回答 默认 最新

  • TongTongBlog 2015-02-12 09:48
    关注

    算是解决了吧,在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();
    }
    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 将USDZ文件转化为带颜色的OBJ文件
  • ¥15 对象代号: , 表单: 不存在!
  • ¥15 WebSocket的问题
  • ¥15 centos上启动kylin后网页报错404
  • ¥20 使用hackrf进行信号收发时接收到的信号幅度太小
  • ¥15 WebSocket的问题
  • ¥15 BDSBAS-B1C和B1C信号有什么不同
  • ¥15 在半圆平面内随机生成点坐标
  • ¥15 系统容量变化的几种多址方式TDMA, CDMA,FDMA,OFDMA 对比,应该给的是一个曲线 图,随着系统容量的增加,几种多址方式性能的对比 图,MATLAB程序仿真折线图
  • ¥15 用visual Studio 写c ++只运行上一个旧代码的运行结果是怎么回事