二进制XML文件行:错误输出类<unknown>

时间:2016-08-10 01:07:16

标签: java android xml android-layout inflate-exception

当我尝试添加前景可绘制时,我在Android 6.0模拟器中出现Error inflating class <unknown>错误。

我的logcat:

Process: com.yasinkacmaz.myapp, PID: 12789
android.view.InflateException: Binary XML file line #14: Binary XML file line #14: Error inflating class <unknown>
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at com.yasinkacmaz.myapp.adapter.NoteAdapter.onCreateViewHolder(NoteAdapter.java:86)
at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5779)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5003)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4913)
at android.support.v7.widget.LayoutState.next(LayoutState.java:100)
at android.support.v7.widget.StaggeredGridLayoutManager.fill(StaggeredGridLayoutManager.java:1555)
at android.support.v7.widget.StaggeredGridLayoutManager.onLayoutChildren(StaggeredGridLayoutManager.java:665)
at android.support.v7.widget.StaggeredGridLayoutManager.onLayoutChildren(StaggeredGridLayoutManager.java:597)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3260)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3069)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3518)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1079)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:122)
at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42)
at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1192)
at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:814)
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.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)

我的相关xml文件:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    card_view:cardUseCompatPadding="true"
    android:clickable="true"
    android:id="@+id/row_note_cardview"
    card_view:cardCornerRadius="3dp"
    card_view:cardElevation="5dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

<!-- line 14 is here --> 
<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/row_note_frame"
    android:foreground="@drawable/state">

 <!-- other layout elements -->

</FrameLayout>
</android.support.v7.widget.CardView>

state.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_selected="true" android:drawable="@null">
    <shape android:shape="rectangle"  >
        <solid android:color="@color/colorSelected"   />
        <stroke  android:width="2dp" android:color="@color/colorSelectedDark"  />
    </shape>
</item>

<item android:state_selected="false" android:drawable="?attr/selectableItemBackgroundBorderless">
    <shape>
        <solid android:color="@android:color/transparent" />
    </shape>
</item>

</selector>

我的build.gradle

compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.android.support:design:23.4.0'

我搜索了Stackoverflow,是的,关于这个主题有很多问题,这个答案指导我:error-inflating-class-unknown-cause

  

检查drawable / background_main,即根布局的背景图像 - 解码位图时VM耗尽内存。使图像尺寸更小。

我的state.xml导致错误,但我需要使用它,我尝试删除FrameLayout并将android:foreground="@drawable/state"添加到CardView,但它并没有帮助我。但是,如果我禁用android:foreground属性,我没有错误。

实际上我正在使用该状态drawable来选择RecyclerView行。这只发生在Android 6.0模拟器上。如果你想在Lolipop和更低版本中看到截图:enter image description here

那我怎么解决这个问题呢?感谢帮助 !

0 个答案:

没有答案