I am getting Error inflating class <unknown>
error in Android 6.0 emulators when I am trying to add foreground drawable.
My 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)
My related xml file :
<?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>
My 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'
I searched Stackoverflow and yes there is so many questions about this topic and this answer guide me : error-inflating-class-unknown-cause
Check your drawable/background_main i.e. the background image of your root layout - the VM runs out of memory when decoding the bitmap. Make the image dimensions smaller.
my state.xml
causes the error but i need to use it, i tried to delete FrameLayout
and add android:foreground="@drawable/state"
to CardView
but it didn't help me. But if i disable android:foreground
attribute, i have no error .
Actually i am using that state drawable for selectable RecyclerView
row. This happens only Android 6.0 emulators. If you want to see screenshot what it looks like in Lolipop and lower:
So how can i fix this? Thanks for help !
build.gradle
. – Karisakarissaandroid:foreground="@color/colorSelected"
there is no error. Actually i specified mystate.xml
causes error, but i must use it for selectableRecyclerView
– Karisakarissa<FrameLayout>
children? Can you try removing them? – Amundandroid:drawable="?attr/selectableItemBackgroundBorderless"
...if you get rid of it, it'll work. I tried it with several versions of android, but its crashing in v23 anyway. – AmundCardView
is the best way; and its working perfect. – Karisakarissa