我正在开发一个应用程序,我想在content_main.xml文件中添加一个Navigation抽屉和一个ListView
当我在content_main.xml中添加ListView或Fragment时,它会抛出异常。例外是InflateException
这是我想要做的描述。
我知道这是一个非常简短的描述,但我没有找到任何方法来更好地描述它 如果你能帮助我,请帮助我。
这是logcat
12-12 11:17:26.923 29725-29725/com.antzion.salmanali.lockapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.antzion.salmanali.lockapp, PID: 29725
android.view.InflateException: Binary XML file line #17: Binary XML file line #17: Error inflating class android.support.design.internal.NavigationMenuItemView
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.support.design.internal.NavigationMenuPresenter$NormalViewHolder.<init>(NavigationMenuPresenter.java:288)
at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.onCreateViewHolder(NavigationMenuPresenter.java:388)
at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.onCreateViewHolder(NavigationMenuPresenter.java:338)
at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5836)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5060)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4970)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2029)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1414)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1377)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:578)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3315)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3124)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3568)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1221)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:2678)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2171)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1931)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
at android.view.Choreographer.doCallbacks(Choreographer.java:670)
at android.view.Choreographer.doFrame(Choreographer.java:606)
at android.view.Ch
我希望有所帮助。
答案 0 :(得分:0)
只需将评论移至答案即可。
使用android:id="@android:id/list"
,这是大多数与列表相关的视图的内置系统列表ID。
您可以像平常一样获得对此的引用,但使用的ID不同于R.id
。
listView = (ListView) findViewById(android.R.id.list);