Fragment加载报错 java.lang.IllegalArgumentException: No view found for id ...

07-16 11:26:49.131  9982  9982 E AndroidRuntime: FATAL EXCEPTION: main
07-16 11:26:49.131  9982  9982 E AndroidRuntime: Process: com.android.gallery3d, PID: 9982
07-16 11:26:49.131  9982  9982 E AndroidRuntime: java.lang.IllegalArgumentException: No view found for id 0x7f0d0070 (com.android.gallery3d:id/state_panel_container) for fragment StatePanel{894ba12 #28 id=0x7f0d0070 StatePanel}
07-16 11:26:49.131  9982  9982 E AndroidRuntime:     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1411)
07-16 11:26:49.131  9982  9982 E AndroidRuntime:     at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1741)
07-16 11:26:49.131  9982  9982 E AndroidRuntime:     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1810)
07-16 11:26:49.131  9982  9982 E AndroidRuntime:     at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797)
07-16 11:26:49.131  9982  9982 E AndroidRuntime:     at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2581)
07-16 11:26:49.131  9982  9982 E AndroidRuntime:     at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2368)
07-16 11:26:49.131  9982  9982 E AndroidRuntime:     at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2323)
07-16 11:26:49.131  9982  9982 E AndroidRuntime:     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2230)
07-16 11:26:49.131  9982  9982 E AndroidRuntime:     at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:700)
07-16 11:26:49.131  9982  9982 E AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:790)
07-16 11:26:49.131  9982  9982 E AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:99)
07-16 11:26:49.131  9982  9982 E AndroidRuntime:     at android.os.Looper.loop(Looper.java:164)
07-16 11:26:49.131  9982  9982 E AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:6494)
07-16 11:26:49.131  9982  9982 E AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
07-16 11:26:49.131  9982  9982 E AndroidRuntime:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
07-16 11:26:49.131  9982  9982 E AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

首先根据ID号找到相应的Fragment container(R.id.state_panel_container), 发现是在加载的时候没有找到相应的container, 即该页面没有那个ID号,也就是没有那个VIEW,

究其原因是getFragmentManager()和 getChildFragmentManager()两种加载方式不同,getFragmentManager()是获取Fragment绑定activity的 FragmentManager,获取到的布局也是activity的布局,

而getChildFragmentManager()获取的是 Fragment自身的FragmentManager,获取到的布局是Fragment自己的布局。

由于代码中发现有一段错误的采用了getFragmentManager()方式,获取的布局自然是Fragment绑定的activity的布局,经审查,该布局中确实没有发现这个VIEW (state_panel_container),导致了这个异常的发生。

posted @ 2018-07-20 10:01  Jokeyyu  阅读(7696)  评论(0编辑  收藏  举报