Related
I followed a tutorial of new component NavigationView in Support Design Library and can't get through this error message :
Error inflating class android.support.design.widget.NavigationView
I tried every workaround here
Error when using any Android Design Support Library Elements
but error message still exists.
xml
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<include layout="#layout/toolbar" android:id="#+id/mainToolBar" />
<fragment android:name="com.ais.cherry.fragment.LoginFragment"
android:id="#+id/loginFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/mainToolBar" />
<fragment android:name="com.ais.cherry.fragment.WaterFallFragment"
android:id="#+id/mainFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/mainToolBar" />
<fragment android:name="com.ais.cherry.fragment.SearchFragment"
android:id="#+id/searchFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/mainToolBar" />
<fragment android:name="com.ais.cherry.fragment.ChatMainFragment"
android:id="#+id/chatMainFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/mainToolBar" />
<fragment android:name="com.ais.cherry.fragment.ProfileFragment"
android:id="#+id/profileFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/mainToolBar" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#android:color/white"
app:itemTextColor="#212121"
app:headerLayout="#layout/drawer_header"
app:menu="#menu/drawer" />
</android.support.v4.widget.DrawerLayout>
build.gradle
buildscript {
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.ais.cherry"
minSdkVersion 16
targetSdkVersion 22
multiDexEnabled true
renderscriptTargetApi 22
renderscriptSupportModeEnabled true
}
dependencies {
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:support-v4:22.2.0'
compile 'com.android.support:design:22.2.0'
compile 'com.android.support:recyclerview-v7:22.2.0'
}
Project build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
styles.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Base application theme. -->
<style name="AppTheme" parent="AppTheme.Base">
</style>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowActionModeOverlay">true</item>
<item name="android:actionModeStyle">#style/AppTheme.ActionModeStyle</item>
<item name="android:windowActionBar">false</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowNoTitle">true</item>
<!-- Support library compatibility -->
<item name="windowActionBarOverlay">true</item>
<!-- ActionBar color -->
<item name="colorPrimary">#E91E63</item>
<!-- Status bar color -->
<item name="colorPrimaryDark">#C2185B</item>
<!-- Window color -->
<item name="android:windowBackground">#color/white</item>
<!-- ActionBar title text -->
<item name="android:titleTextStyle">#style/AppTheme.MyActionBarTitleText</item>
<item name="colorAccent">#9E9E9E</item>
<item name="drawerArrowStyle">#style/AppTheme.MyDrawerArrowStyle</item>
<!-- color for actionMenu-->
<item name="actionMenuTextColor">#FFFFFF</item>
<item name="android:actionMenuTextColor">#FFFFFF</item>
<!-- android:textColorSecondary is the color of the menu
overflow icon (three vertical dots) -->
<item name="android:textColorPrimary">#212121</item>
<item name="android:textColorSecondary">#FFFFFF</item>
<!--Navigation bar color-->
<item name="android:navigationBarColor">#E91E63</item>
<!--Status bar color-->
<item name="android:statusBarColor">#C2185B</item>
</style>
Any help would be appreciated!
Edit -- add #menu/drawer & #menu/drawer_header & stacktrace
drawer.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_first_fragment"
android:icon="#drawable/home_view"
android:checked="true"
android:title="#string/main"/>
<item
android:id="#+id/nav_second_fragment"
android:icon="#drawable/comment_view"
android:title="#string/chat"/>
<item
android:id="#+id/nav_third_fragment"
android:icon="#drawable/user_view"
android:title="#string/profile"/>
<item android:title="#string/search">
<menu>
<item
android:title="#string/clothes"/>
<item
android:title="#string/pants"/>
</menu>
</item>
</group>
</menu>
drawer_header.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="192dp"
android:background="?attr/colorPrimaryDark"
android:padding="16dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark"
android:gravity="bottom">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/title"
android:textColor="#android:color/white"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"/>
</LinearLayout>
StackTrace (only part of them)
It thrown out three exceptions as below : all points out that the problems is caused by the line of "setContentView(layout)" at in layout.xml.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ais.cherry/com.ais.cherry.activity.FirstActivity}: android.view.InflateException: Binary XML file line #32: Error inflating class android.support.design.widget.NavigationView
Caused by: android.view.InflateException: Binary XML file line #32: Error inflating class android.support.design.widget.NavigationView
Caused by: java.lang.reflect.InvocationTargetException
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
Actually it is not the matter of the primarycolortext, upgrading or downgrading the dependencies.This problem will likely occur when the version of your appcompat library and design support library doesn't match.
Example of matching condition
compile 'com.android.support:appcompat-v7:23.1.1' // appcompat library
compile 'com.android.support:design:23.1.1' //design support library
I had similar error.
When i use
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#673AB7</item>
<item name="colorPrimaryDark">#512DA8</item>
<item name="colorAccent">#00BCD4</item>
<item name="android:textColorPrimary">#212121</item>
<item name="android:textColorSecondary">#727272</item>
</style>
works for me when i remove the android:textColorPrimary and android:textColorSecondary theme items.
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#673AB7</item>
<item name="colorPrimaryDark">#512DA8</item>
<item name="colorAccent">#00BCD4</item>
</style>
Try working with a very simple App theme to start off with.
EDIT:
This tutorial will help.
My understanding is that using "android:textColorPrimary" requires minimum api level 21. Using the same tag without "android:" uses the design support library. Any support library widget will try to find the "textColorPrimary" item instead of "android:textColorPrimary" and if it fails to find the same it throws the above mentioned error.
I also had same error. In my case some of the resources were in drawable-v21 only. Copy those resources to drawable folder also. This solved the issue for me.
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
This is the main problem.
If you have already migrated to androidx, you should change your layout xml
from
<android.support.design.widget.NavigationView ... />
to
<com.google.android.material.navigation.NavigationView ... />
I had the same error, I resolved it by adding app:itemTextColor="#color/a_color" to my navigation view :
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="left"
app:headerLayout="#layout/layout_drawer_header"
app:menu="#menu/drawer_menu"
app:itemTextColor="#color/primary"/>
You can still use android:textColorPrimary and android:textColorSecondary in your theme with this method.
Well
So I was trying to fix this error. And none worked for me. I was not able to figure out solution.
Scenario:
I was just going to made a Navigation Drawer Project inside Android Studio 2.1.2
And when I try to change the default Android icon in nav_header_main.xml I was getting some weird errors. I figured out that I was droping my PNG logo into the ...\app\src\main\res\drawable-21. When I try to put my PNG logo in ...\app\src\main\res\drawable bam! All weird errors go away.
Following are some of stack trace when I was putting PNG into drawable-21 folder:
08-17 17:29:56.237 6644-6678/myAppName E/dalvikvm: Could not find class 'android.util.ArrayMap', referenced from method com.android.tools.fd.runtime.Restarter.getActivities
08-17 17:30:01.674 6644-6644/myAppName E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{myAppName.MainActivity}: android.view.InflateException: Binary XML file line #16: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2372)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2424)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3956)
at android.app.ActivityThread.access$700(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1394)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5433)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:924)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:691)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:613)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at edu.uswat.fwd82.findmedoc.MainActivity.onCreate(MainActivity.java:22)
at android.app.Activity.performCreate(Activity.java:5179)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1146)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2336)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2424)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3956)
at android.app.ActivityThread.access$700(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1394)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5433)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:924)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:691)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:587)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at edu.uswat.fwd82.findmedoc.MainActivity.onCreate(MainActivity.java:22)
at android.app.Activity.performCreate(Activity.java:5179)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1146)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2336)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2424)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3956)
at android.app.ActivityThread.access$700(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1394)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5433)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:924)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:691)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #14: Error inflating class ImageView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.support.design.internal.NavigationMenuPresenter.inflateHeaderView(NavigationMenuPresenter.java:189)
at android.support.design.widget.NavigationView.inflateHeaderView(NavigationView.java:262)
at android.support.design.widget.NavigationView.<init>(NavigationView.java:173)
at android.support.design.widget.NavigationView.<init>(NavigationView.java:95)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:587)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at edu.uswat.fwd82.findmedoc.MainActivity.onCreate(MainActivity.java:22)
at android.app.Activity.performCreate(Activity.java:5179)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1146)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2336)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2424)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3956)
at android.app.ActivityThread.access$700(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1394)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5433)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:924)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:691)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.content.res.ResourcesEx.getThemeDrawable(ResourcesEx.java:459)
at android.content.res.ResourcesEx.loadDrawable(ResourcesEx.java:435)
at android.content.res.TypedArray.getDrawable(TypedArray.java:609)
at android.widget.ImageView.<init>(ImageView.java:120)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:57)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:53)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:980)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:1039)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:
As you can see the above Stack Trace include:
android.support.design.widget.NavigationView.inflateHeaderView(NavigationView.java:262)
at android.support.design.widget.NavigationView.(NavigationView.java:173)
at android.support.design.widget.NavigationView.(NavigationView.java:95)
I solved it downgrading in gradle from
compile 'com.android.support:design:23.1.0'
to
compile 'com.android.support:design:23.0.1'
It seems like I always get problems when I update any component of Android Studio. Getting tired of it.
None of the above fixes worked for me.
What worked for me was changing
<item name="android:textColorSecondary">#FFFFFF</item>
to
<item name="android:textColorSecondary">#color/colorWhite</item>
You obviously need to add colorWhite to your colors.xml
Following below steps will surely remove this error.
Find the widget causing the error.
Go the layout file where that widget is declared.
Check for all the resources (drawables etc.) used in that file.
Then make sure that resource is there in all versions of drawables (drawable-v21,drawable etc.)
Cheers!!
As Parag Naik correctly mentions (and Lạng Hoàng expands on), the problem arises when setting textColorPrimary to something other than a color state list. So you could set textColorPrimary as a state list. There is an issue in the android bug tracker about colorPrimary being a state list with only one color: https://code.google.com/p/android/issues/detail?id=172353
So for your theme in styles.xml:
<style name="Base.Theme.Hopster" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="colorAccent">#color/accent</item>
<item name="android:textColorPrimary">#color/primary_color_statelist</item>
</style>
And the actual primary_color_statelist.xml file:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- This is used when the Navigation Item is checked -->
<item android:color="#color/primary_text_selected" android:state_checked="true" />
<!-- This is the default text color -->
<item android:color="#color/primary_text" />
</selector>
In my case, I had the same error when I run the app in kitkat API 19 version device. I figured out the problem; I had some drawable resources which was in the drawable-v21 directory (Which is used for versions from API 21 Lollipop). I just put the same resources in the "Drawable" folder to work with the version below API 21. It works. You can put it on the corresponding directory
For me, I encountered this error many times,
Error inflating class android.support.design.widget.NavigationView #28 and #29
The solution that works for me is that you must match your support design library and your support appcompat library.
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
For me they must match. :) It works for me!
Just for who still get to this issue. I got to the same problem but all the solutions here is not work for me.
Just take alook on NavigationView class with cue from logcat, i found the issue come form this line of code:
itemTextColor = this.createDefaultColorStateList(16842806);
So, it seem related to itemTextColor as Aenur56 mentioned. So i tried with Aenur56's solution but it doesn't work.
Take a look on the line of code above, i notice that there is ColorStateList. So i create one then set for itemTextColor then it work.
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#00FF00" android:state_checked="true" />
<item android:color="#000000" />
</selector>
Hope it help!
None of the solutions above helped me. I found this on some other webpage and it worked for me - "In project.properties of design library set target to 21 or highest available, then clean design lib, appcomapt and your project and enjoy"
Hope it will help!
Make sure your drawables for the menu are in the correct folder, mine where put in drawablev21 hence this caused a nullpointer to the resource.
Fixed it buy moving my icons to drawables folder
Generic way of solving issues like Error inflating class X:
check cause stack trace and there should be Resources$NotFoundException like this:
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f0b0066
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:190)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2094)
at android.content.res.Resources.getLayout(Resources.java:1111)
at android.view.LayoutInflater.inflate(LayoutInflater.java:424)
Resource ID is actually exact integer from generated R.java file.
Find 0x7f0b0066 which will point to the xml file which could not be inflated(found).
In most cases that's because directory layout doesn't have this resource, but some layout-XXX has.
And solution is to put resource into all required directories. Or just at least into layout.
In my case i had
<android.support.design.widget.NavigationView...
and in app config:
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
So I changed the XML to:
com.google.android.material.navigation.NavigationView...
I had the same problem after upgrading the support library and none of the answers worked for me. Finally I solved downloading latest version of build tools and upgrading in build.gradle to buildToolsVersion "23.0.1"
One thing to double-check is that you have applied your theme correctly in your AndroidManifest.xml file. In my case, I had omitted the android:theme attribute. E.g:
<application ... android:theme="#style/Your.Theme.Here" ... >
BETTER I UPGRADED com.android.support:appcompat-v7:23.1.0
as #Ton said downgrade compile 'com.android.support:design:23.1.0'
BUT Why not to upgrade com.android.support:appcompat-v7:23.1.1
Final upgraded worked for me enjoy
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
So why to use older library. I think is now better to use both design and compact upgraded.
I was also having this same issue, after looking nearly 3 hours I find out that the problem was in my drawable_menu.xml file, it was wrongly written :D
This error can be caused due to reasons as mentioned below.
This problem will likely occur when the version of your appcompat library and design support library doesn't match.
Example of matching condition
compile 'com.android.support:appcompat-v7:24.2.0' // appcompat library
compile 'com.android.support:design:24.2.0' //design support library
If your theme file in styles have only these two,
<item name="colorPrimary">#4A0958</item>
<item name="colorPrimaryDark">#4A0958</item>
then add ColorAccent too. It should look somewhat like this.
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#4A0958</item>
<item name="colorPrimaryDark">#4A0958</item>
<item name="colorAccent">#4A0958</item>
</style>
It's weird but clean project and rebuild project worked for me.
I found solution...
if you used app:srcCompat change to android:src
this solution worked for me :)
I was facing this error in Xamarin. This was due to some files that were present in drawable-v21 folder. So I copied those files (probably icon files) to the drawable folder and the error was gone.
After solving a JDK zero value error, now I'm facing this one. I did a little research, but it seems I can't get to the point. Here is the log error:
FATAL EXCEPTION: main
E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{.MainActivity}: android.content.res.Resources$NotFoundException: File res/drawable/abc_ic_ab_back_material.xml from drawable resource ID #0x7f020013
E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2204)
E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2254)
E/AndroidRuntime: at android.app.ActivityThread.access$600(ActivityThread.java:141)
E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime: at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5069)
E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime: Caused by: android.content.res.Resources$NotFoundException: File res/drawable/abc_ic_ab_back_material.xml from drawable resource ID #0x7f020013
E/AndroidRuntime: at android.content.res.Resources.loadDrawable(Resources.java:1953)
E/AndroidRuntime: at android.content.res.Resources.getDrawable(Resources.java:660)
E/AndroidRuntime: at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:354)
E/AndroidRuntime: at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:193)
E/AndroidRuntime: at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:181)
E/AndroidRuntime: at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:689)
E/AndroidRuntime: at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:186)
E/AndroidRuntime: at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:77)
E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:83)
E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV7.<init>(AppCompatDelegateImplV7.java:146)
E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:28)
E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:41)
E/AndroidRuntime: at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:193)
E/AndroidRuntime: at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:173)
E/AndroidRuntime: at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:511)
E/AndroidRuntime: at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:71)
E/AndroidRuntime: at .MainActivity.onCreate(MainActivity.java:29)
E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:5104)
E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1092)
E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2254)
E/AndroidRuntime: at android.app.ActivityThread.access$600(ActivityThread.java:141)
E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime: at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5069)
E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime: Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #17: invalid drawable tag vector
E/AndroidRuntime: at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:881)
E/AndroidRuntime: at android.graphics.drawable.Drawable.createFromXml(Drawable.java:822)
E/AndroidRuntime: at android.content.res.Resources.loadDrawable(Resources.java:1950)
E/AndroidRuntime: at android.content.res.Resources.getDrawable(Resources.java:660)
E/AndroidRuntime: at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:354)
E/AndroidRuntime: at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:193)
E/AndroidRuntime: at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:181)
E/AndroidRuntime: at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:689)
E/AndroidRuntime: at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:186)
E/AndroidRuntime: at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:77)
E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:83)
E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV7.<init>(AppCompatDelegateImplV7.java:146)
E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:28)
E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:41)
E/AndroidRuntime: at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:193)
E/AndroidRuntime: at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:173)
E/AndroidRuntime: at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:511)
E/AndroidRuntime: at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:71)
E/AndroidRuntime: at .MainActivity.onCreate(MainActivity.java:29)
E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:5104)
E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1092)
E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2254)
E/AndroidRuntime: at android.app.ActivityThread.access$600(ActivityThread.java:141)
E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime: at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5069)
E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
I'm really confused about what it can be, I read and can't get to the error:
My app:gradle is this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "me.me2.com.myapp"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.google.firebase:firebase-storage:9.4.0'
compile 'com.google.firebase:firebase-database:9.4.0'
compile 'com.google.firebase:firebase-auth:9.4.0'
compile 'com.firebaseui:firebase-ui-database:0.4.4'
compile 'com.squareup.picasso:picasso:2.5.2'
}
apply plugin: 'com.google.gms.google-services'
Here is my style folder:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="Divider">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">1dp</item>
<item name="android:background">?android:attr/listDivider</item>
</style>
</resources>
And my mainactivity.class if needed:
public class MainActivity extends AppCompatActivity {
VideoView videoView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// VideoView
videoView = (VideoView) findViewById(R.id.videoview);
videoView.setVideoURI(Uri.parse("android.resource://"+getPackageName() + "/" +R.raw.video));
videoView.requestFocus();
/**
* Loop
*/
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
videoView.start();
mp.setLooping(true);
}
});
}
public void Login(View view) {
Intent intent = new Intent(this, FragmentMain.class);
startActivity(intent);
// finish();
}
public void Registro(View view) {
Intent intent = new Intent(this, Registro.class);
startActivity(intent);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Thanks.
IF you're using Gradle Plugin 2.0, you need to make changes in your gradle:
// Gradle Plugin 2.0+
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
If you are using Gradle 1.5 you’ll use instead of previus:
// Gradle Plugin 1.5
android {
defaultConfig {
// Stops the Gradle plugin's automatic rasterization of vectors
generatedDensities = []
}
// Flag to tell aapt to keep the attribute ids around
// This is handled for you by the 2.0+ Gradle Plugin
aaptOptions {
additionalParameters "--no-version-vectors"
}
}
Check also: Update Android Support Library to 23.2.0 cause error: XmlPullParserException Binary XML file line #17<vector> tag requires viewportWidth > 0.
Android Support Library Ref.: Support Vector Drawables and Animated Vector Drawables.
Also update Android Support dependencies from
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
to
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support:design:24.2.0'
compile 'com.android.support:recyclerview-v7:24.2.0'
compile 'com.android.support:cardview-v7:24.2.0'
as you're already using build-tools in version of 24.0.2.
If any of the other solutions does not work, you can add this line in your Activity
static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
and of course, update your gradle and appcompat to the latest versions. This worked in my case.
None of these worked for me. But this did:
Change
android:src="#drawable/your_drawable"
to
app:srcCompat="#drawable/your_drawable"
I ran into this issue in Xamarin.Android with Xamarin.Android.Support.Design 24.0.2. Here is how I solved it:
Added the following line to my Application class OnCreate:
AppCompatDelegate.CompatVectorFromResourcesEnabled = true;
Replaced:
var upArrow = ContextCompat.GetDrawable(this, Resource.Drawable.abc_ic_ab_back_material);
With:
var upArrow = ResourcesCompat.GetDrawable(Resources, Resource.Drawable.abc_ic_ab_back_material, null);
Since this page is the first result of google android.content.res.Resources$NotFoundException: File res/drawable/, I want to share that this exception might caused by your foo.xml contains improper code.
e.g. foo.xml:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background">
<shape>
<size android:height="#android:style/Widget.ProgressBar.Horizontal" />
<corners android:radius="5dip" />
<gradient
android:startColor="#000000"
android:centerY="0.75"
android:angle="270"
/>
</shape>
</item>
</layer-list>
This xml contains <size android:height="#android:style/Widget.ProgressBar.Horizontal" /> which compiled successfully but throws exception at Runtime, vary in different app.
use like this in your Activity:
public class MainActivity extends AppCompatActivity {
static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
...
}
and this in your build.gradle :
android {
...
defaultConfig {
....
vectorDrawables.useSupportLibrary = true
}
}
and in your xml:
app:srcCompat="#drawable/your_icon"
For me the issue was while running the app on Kitkat version I got this runtime crash.
Issue:
android {
compileSdkVersion 28
defaultConfig {
//Change this to true to enable multidex support for Kitkat
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
}
Solution:
//comment the line of vector support
android {
//Change this to true to enable multidex support for Kitkat
multiDexEnabled true
//vectorDrawables.useSupportLibrary = true
}
Ok, i just solved my problem, the problem was my gradle outdated and my sdk , so if anyone is running with this problem just do this steps
1.- Make sure your libs are updated as piotrek1543 says above
2.- Update your sdk if is necesary
3.- Update your gradle files (VERY IMPORTANT)
just go to the project gradle and add this
classpath 'com.android.tools.build:gradle:2.1.0'
then go to your app project > app > graddle > graddlewrapper.properties and add
distributionUrl=https://services.gradle.org/distributions/gradle-2.10-all.zip
4.- change your compile compileSdkVersion to 24
and your buildToolsVersion "24.0.2" (MAKE SURE YOUR DEPENDENCES ARE UP TO DATE WITH THE SDK)
Have fun
I have tried all solutions mentioned above. Nothing worked for me. The only thing worked for me is very simple is to update all support libraries to latest version as this bug has been fixed in it. So i simple did the below thing in gradle file; updated SDK and support to 25.
android {
compileSdkVersion 25
buildToolsVersion "25"
defaultConfig {
targetSdkVersion 25
}
}
In dependencies
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
compile 'com.android.support:recyclerview-v7:25.1.0'
Not specifically related to your question, but maybe can solve this problem for all that find themselves here while searching for that error.
For me was the problem with SVG file that I have imported into my project. One of the paths in XML has empty pathData and that was causing the crash on some devices like Pixel XL, Samsung Galaxy S7,...
So double check imported XML for an image if you are using SVG as your image source.
I had this problem.
In your Application class, in the onCreate() method, add:
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
... and also use AppCompatImageView instead of ImageView.
Ex :
BaseApplication.class :
public class BaseApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
//Your other code here...
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
}
XML :
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/yourIvId"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
In my case, the issue was about using vector drawable.
The spec of the test device was Huawei EVA-L19, Android: Marshmallow
Using srcCompat instead of src resolved my problem.
In my case, the problem was wrong super-type. I added image view dynamically, and used ImageView instead of AppCompatImageView. Choosing the right super class solved the issue.
I tried all the answers above but no success because of clarity most of the time.
Just do this:
In the launch_background.xml file, replace mipmap with drawable
Copy the icon image that should be your app icon and paste it in the drawable folder
At the end the launch_background.xml file should look like below.
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/blue" />
<!-- You can insert your own image assets here -->
<item>
<bitmap android:gravity="center" android:src="#drawable/ic_launcher" />
</item>
</layer-list>
Changing the kotlin-stdlib dependency from:
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:1.2.0"
to
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.2.0"
fixed the error.
in my case the XML contained android:endX that supports from 24 and up.
If you are using ?attr inside your drawable, this could be the reason of error.
consider replacing it with Vector Drawable so it can be used in all android versions:
Replace
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="?attr/navigationIconColor" />
</shape>
</item>
</selector>
With:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="37dp"
android:height="5dp"
android:viewportWidth="37"
android:viewportHeight="5">
<path
android:pathData="M2.5,0h32C35.9,0 37,1.1 37,2.5l0,0C37,3.9 35.9,5 34.5,5h-32C1.1,5 0,3.9 0,2.5l0,0C0,1.1 1.1,0 2.5,0z"
android:fillColor="?attr/navigationIconColor"/>
</vector>
The above methods didn’t work for me. I solved it by adding image of every size and used android:src as well it worked.
See the answer here https://stackoverflow.com/a/64537207/11669081
for running the app on Kitkat version make use of VectorDrawableCompat like below
ivBg.setImageDrawable(VectorDrawableCompat.create(resources, R.drawable.ic_bg_minicash_single,context?.theme))
No need to change ImageView into AppCompatImageView explicitly AppCompatActivity will automatically convert it.
I am getting a bug using the official FloatingActionButton from Google's support design library.
Here is my LogCat.
android.view.InflateException: Binary XML file line #34: Error inflating class android.support.design.widget.FloatingActionButton
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method)
at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:655)
at android.view.LayoutInflater.inflate(Unknown Source)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at ---.---.com.---.SubCategoryFragment.onCreateView(SubCategoryFragment.java:47)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1789)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:955)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:458)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:117)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
... 24 more
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.graphics.drawable.Drawable android.graphics.drawable.Drawable$ConstantState.newDrawable()' on a null object reference
at android.graphics.drawable.LayerDrawable$ChildDrawable.<init>(LayerDrawable.java:968)
at android.graphics.drawable.LayerDrawable$LayerState.<init>(LayerDrawable.java:1014)
at android.graphics.drawable.RippleDrawable$RippleState.<init>(RippleDrawable.java:910)
at android.graphics.drawable.RippleDrawable.createConstantState(RippleDrawable.java:901)
at android.graphics.drawable.RippleDrawable.createConstantState(RippleDrawable.java:90)
at android.graphics.drawable.LayerDrawable.mutate(LayerDrawable.java:932)
at android.graphics.drawable.RippleDrawable.mutate(RippleDrawable.java:891)
at android.view.View.applyBackgroundTint(View.java:16324)
at android.view.View.setBackgroundDrawable(View.java:16193)
at android.support.design.widget.FloatingActionButton.access$201(FloatingActionButton.java:56)
at android.support.design.widget.FloatingActionButton$1.setBackgroundDrawable(FloatingActionButton.java:118)
at android.support.design.widget.FloatingActionButtonLollipop.setBackgroundDrawable(FloatingActionButtonLollipop.java:75)
at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:131)
at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:79)
... 27 more
The only line that points to my app is where it inflates the xml file, and the line in that file which is my FloatingActionButton.
<android.support.design.widget.FloatingActionButton
android:id="#+id/myFABSubCat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_margin="16dp"
android:backgroundTint="#color/accent"
android:src="#drawable/add_icon"
app:borderWidth="0dp"
app:elevation="4sp" />
Extra info:
Here is my app theme:
<resources>
<!-- Base application theme. -->
<style name="MBTIAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primaryDark</item>
<item name="colorAccent">#color/accent</item>
<item name="android:windowContentOverlay">#null</item>
</style>
<style name="ThemeNoActionBar" parent="MBTIAppTheme">
<item name="windowActionBar">false</item>
</style>
</resources>
Yes, I am using an AppCompatActivity.
I noticed I am using an older version of appcompat:
com.android.support:appcompat-v7:22.1.1
This seems to be up to date:
compile 'com.android.support:design:22.2.0'
Also,
minSdkVersion 16
targetSdkVersion 22
Now, I do set the Visibility to GONE in some case for my FAB, but this is after it inflates so that can't be the issue.
Now, this works with my 5.1 device, but the users who have issues have 5.0.
Is this a known bug or maybe I am doing something wrong?
com.android.support:appcompat-v7:21+ added support for tinting widgets on devices running pre android 5.1 (API Level 21). To make use of it make sure you extend or set the AppCompat Theme and use app:backgroundTint instead of android:backgroundTint.
Example:
<android.support.design.widget.FloatingActionButton
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:src="#drawable/icon"
app:backgroundTint="#color/accent"
app:borderWidth="0dp" />
Just replace
<android.support.design.widget.FloatingActionButton
...
...
android:backgroundTint
/>
to
<android.support.design.widget.FloatingActionButton
...
...
app:backgroundTint
/>
If you're using a VectorDrawableCompat (Vector asset) you should use:
app:srcCompat="#drawable/x"
instead of:
android:src="#drawable/x"
I had the same issue and tried different solution. But the one that worked for me was to ensure that appcompat and design support library versions are the same.
for example:
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:design:23.2.0'
Just change android to app:
android:backgroundTint="#color/accent"
To:
app:backgroundTint="#color/accent"
Another way to get this message is if you accidentally specified different versions of the appcompat library in different modules. This is likely to happen when you create a new module, since Android Studio defaults to the most current version.
For a tidy way of managing this in multi-module projects, see: In Gradle, how do I declare common dependencies in a single place?
in my case, it was because of the false configuration of activity theme. problem was solved after i changed app theme to Theme.AppCompat.xxx.
I followed a tutorial of new component NavigationView in Support Design Library and can't get through this error message :
Error inflating class android.support.design.widget.NavigationView
I tried every workaround here
Error when using any Android Design Support Library Elements
but error message still exists.
xml
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<include layout="#layout/toolbar" android:id="#+id/mainToolBar" />
<fragment android:name="com.ais.cherry.fragment.LoginFragment"
android:id="#+id/loginFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/mainToolBar" />
<fragment android:name="com.ais.cherry.fragment.WaterFallFragment"
android:id="#+id/mainFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/mainToolBar" />
<fragment android:name="com.ais.cherry.fragment.SearchFragment"
android:id="#+id/searchFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/mainToolBar" />
<fragment android:name="com.ais.cherry.fragment.ChatMainFragment"
android:id="#+id/chatMainFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/mainToolBar" />
<fragment android:name="com.ais.cherry.fragment.ProfileFragment"
android:id="#+id/profileFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/mainToolBar" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#android:color/white"
app:itemTextColor="#212121"
app:headerLayout="#layout/drawer_header"
app:menu="#menu/drawer" />
</android.support.v4.widget.DrawerLayout>
build.gradle
buildscript {
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.ais.cherry"
minSdkVersion 16
targetSdkVersion 22
multiDexEnabled true
renderscriptTargetApi 22
renderscriptSupportModeEnabled true
}
dependencies {
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:support-v4:22.2.0'
compile 'com.android.support:design:22.2.0'
compile 'com.android.support:recyclerview-v7:22.2.0'
}
Project build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
styles.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Base application theme. -->
<style name="AppTheme" parent="AppTheme.Base">
</style>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowActionModeOverlay">true</item>
<item name="android:actionModeStyle">#style/AppTheme.ActionModeStyle</item>
<item name="android:windowActionBar">false</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowNoTitle">true</item>
<!-- Support library compatibility -->
<item name="windowActionBarOverlay">true</item>
<!-- ActionBar color -->
<item name="colorPrimary">#E91E63</item>
<!-- Status bar color -->
<item name="colorPrimaryDark">#C2185B</item>
<!-- Window color -->
<item name="android:windowBackground">#color/white</item>
<!-- ActionBar title text -->
<item name="android:titleTextStyle">#style/AppTheme.MyActionBarTitleText</item>
<item name="colorAccent">#9E9E9E</item>
<item name="drawerArrowStyle">#style/AppTheme.MyDrawerArrowStyle</item>
<!-- color for actionMenu-->
<item name="actionMenuTextColor">#FFFFFF</item>
<item name="android:actionMenuTextColor">#FFFFFF</item>
<!-- android:textColorSecondary is the color of the menu
overflow icon (three vertical dots) -->
<item name="android:textColorPrimary">#212121</item>
<item name="android:textColorSecondary">#FFFFFF</item>
<!--Navigation bar color-->
<item name="android:navigationBarColor">#E91E63</item>
<!--Status bar color-->
<item name="android:statusBarColor">#C2185B</item>
</style>
Any help would be appreciated!
Edit -- add #menu/drawer & #menu/drawer_header & stacktrace
drawer.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_first_fragment"
android:icon="#drawable/home_view"
android:checked="true"
android:title="#string/main"/>
<item
android:id="#+id/nav_second_fragment"
android:icon="#drawable/comment_view"
android:title="#string/chat"/>
<item
android:id="#+id/nav_third_fragment"
android:icon="#drawable/user_view"
android:title="#string/profile"/>
<item android:title="#string/search">
<menu>
<item
android:title="#string/clothes"/>
<item
android:title="#string/pants"/>
</menu>
</item>
</group>
</menu>
drawer_header.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="192dp"
android:background="?attr/colorPrimaryDark"
android:padding="16dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark"
android:gravity="bottom">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/title"
android:textColor="#android:color/white"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"/>
</LinearLayout>
StackTrace (only part of them)
It thrown out three exceptions as below : all points out that the problems is caused by the line of "setContentView(layout)" at in layout.xml.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ais.cherry/com.ais.cherry.activity.FirstActivity}: android.view.InflateException: Binary XML file line #32: Error inflating class android.support.design.widget.NavigationView
Caused by: android.view.InflateException: Binary XML file line #32: Error inflating class android.support.design.widget.NavigationView
Caused by: java.lang.reflect.InvocationTargetException
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
Actually it is not the matter of the primarycolortext, upgrading or downgrading the dependencies.This problem will likely occur when the version of your appcompat library and design support library doesn't match.
Example of matching condition
compile 'com.android.support:appcompat-v7:23.1.1' // appcompat library
compile 'com.android.support:design:23.1.1' //design support library
I had similar error.
When i use
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#673AB7</item>
<item name="colorPrimaryDark">#512DA8</item>
<item name="colorAccent">#00BCD4</item>
<item name="android:textColorPrimary">#212121</item>
<item name="android:textColorSecondary">#727272</item>
</style>
works for me when i remove the android:textColorPrimary and android:textColorSecondary theme items.
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#673AB7</item>
<item name="colorPrimaryDark">#512DA8</item>
<item name="colorAccent">#00BCD4</item>
</style>
Try working with a very simple App theme to start off with.
EDIT:
This tutorial will help.
My understanding is that using "android:textColorPrimary" requires minimum api level 21. Using the same tag without "android:" uses the design support library. Any support library widget will try to find the "textColorPrimary" item instead of "android:textColorPrimary" and if it fails to find the same it throws the above mentioned error.
I also had same error. In my case some of the resources were in drawable-v21 only. Copy those resources to drawable folder also. This solved the issue for me.
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
This is the main problem.
If you have already migrated to androidx, you should change your layout xml
from
<android.support.design.widget.NavigationView ... />
to
<com.google.android.material.navigation.NavigationView ... />
I had the same error, I resolved it by adding app:itemTextColor="#color/a_color" to my navigation view :
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="left"
app:headerLayout="#layout/layout_drawer_header"
app:menu="#menu/drawer_menu"
app:itemTextColor="#color/primary"/>
You can still use android:textColorPrimary and android:textColorSecondary in your theme with this method.
Well
So I was trying to fix this error. And none worked for me. I was not able to figure out solution.
Scenario:
I was just going to made a Navigation Drawer Project inside Android Studio 2.1.2
And when I try to change the default Android icon in nav_header_main.xml I was getting some weird errors. I figured out that I was droping my PNG logo into the ...\app\src\main\res\drawable-21. When I try to put my PNG logo in ...\app\src\main\res\drawable bam! All weird errors go away.
Following are some of stack trace when I was putting PNG into drawable-21 folder:
08-17 17:29:56.237 6644-6678/myAppName E/dalvikvm: Could not find class 'android.util.ArrayMap', referenced from method com.android.tools.fd.runtime.Restarter.getActivities
08-17 17:30:01.674 6644-6644/myAppName E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{myAppName.MainActivity}: android.view.InflateException: Binary XML file line #16: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2372)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2424)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3956)
at android.app.ActivityThread.access$700(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1394)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5433)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:924)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:691)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:613)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at edu.uswat.fwd82.findmedoc.MainActivity.onCreate(MainActivity.java:22)
at android.app.Activity.performCreate(Activity.java:5179)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1146)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2336)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2424)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3956)
at android.app.ActivityThread.access$700(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1394)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5433)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:924)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:691)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:587)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at edu.uswat.fwd82.findmedoc.MainActivity.onCreate(MainActivity.java:22)
at android.app.Activity.performCreate(Activity.java:5179)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1146)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2336)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2424)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3956)
at android.app.ActivityThread.access$700(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1394)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5433)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:924)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:691)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #14: Error inflating class ImageView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.support.design.internal.NavigationMenuPresenter.inflateHeaderView(NavigationMenuPresenter.java:189)
at android.support.design.widget.NavigationView.inflateHeaderView(NavigationView.java:262)
at android.support.design.widget.NavigationView.<init>(NavigationView.java:173)
at android.support.design.widget.NavigationView.<init>(NavigationView.java:95)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:587)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at edu.uswat.fwd82.findmedoc.MainActivity.onCreate(MainActivity.java:22)
at android.app.Activity.performCreate(Activity.java:5179)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1146)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2336)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2424)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3956)
at android.app.ActivityThread.access$700(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1394)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5433)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:924)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:691)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.content.res.ResourcesEx.getThemeDrawable(ResourcesEx.java:459)
at android.content.res.ResourcesEx.loadDrawable(ResourcesEx.java:435)
at android.content.res.TypedArray.getDrawable(TypedArray.java:609)
at android.widget.ImageView.<init>(ImageView.java:120)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:57)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:53)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:980)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:1039)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:
As you can see the above Stack Trace include:
android.support.design.widget.NavigationView.inflateHeaderView(NavigationView.java:262)
at android.support.design.widget.NavigationView.(NavigationView.java:173)
at android.support.design.widget.NavigationView.(NavigationView.java:95)
I solved it downgrading in gradle from
compile 'com.android.support:design:23.1.0'
to
compile 'com.android.support:design:23.0.1'
It seems like I always get problems when I update any component of Android Studio. Getting tired of it.
None of the above fixes worked for me.
What worked for me was changing
<item name="android:textColorSecondary">#FFFFFF</item>
to
<item name="android:textColorSecondary">#color/colorWhite</item>
You obviously need to add colorWhite to your colors.xml
Following below steps will surely remove this error.
Find the widget causing the error.
Go the layout file where that widget is declared.
Check for all the resources (drawables etc.) used in that file.
Then make sure that resource is there in all versions of drawables (drawable-v21,drawable etc.)
Cheers!!
As Parag Naik correctly mentions (and Lạng Hoàng expands on), the problem arises when setting textColorPrimary to something other than a color state list. So you could set textColorPrimary as a state list. There is an issue in the android bug tracker about colorPrimary being a state list with only one color: https://code.google.com/p/android/issues/detail?id=172353
So for your theme in styles.xml:
<style name="Base.Theme.Hopster" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="colorAccent">#color/accent</item>
<item name="android:textColorPrimary">#color/primary_color_statelist</item>
</style>
And the actual primary_color_statelist.xml file:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- This is used when the Navigation Item is checked -->
<item android:color="#color/primary_text_selected" android:state_checked="true" />
<!-- This is the default text color -->
<item android:color="#color/primary_text" />
</selector>
In my case, I had the same error when I run the app in kitkat API 19 version device. I figured out the problem; I had some drawable resources which was in the drawable-v21 directory (Which is used for versions from API 21 Lollipop). I just put the same resources in the "Drawable" folder to work with the version below API 21. It works. You can put it on the corresponding directory
For me, I encountered this error many times,
Error inflating class android.support.design.widget.NavigationView #28 and #29
The solution that works for me is that you must match your support design library and your support appcompat library.
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
For me they must match. :) It works for me!
Just for who still get to this issue. I got to the same problem but all the solutions here is not work for me.
Just take alook on NavigationView class with cue from logcat, i found the issue come form this line of code:
itemTextColor = this.createDefaultColorStateList(16842806);
So, it seem related to itemTextColor as Aenur56 mentioned. So i tried with Aenur56's solution but it doesn't work.
Take a look on the line of code above, i notice that there is ColorStateList. So i create one then set for itemTextColor then it work.
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#00FF00" android:state_checked="true" />
<item android:color="#000000" />
</selector>
Hope it help!
None of the solutions above helped me. I found this on some other webpage and it worked for me - "In project.properties of design library set target to 21 or highest available, then clean design lib, appcomapt and your project and enjoy"
Hope it will help!
Make sure your drawables for the menu are in the correct folder, mine where put in drawablev21 hence this caused a nullpointer to the resource.
Fixed it buy moving my icons to drawables folder
Generic way of solving issues like Error inflating class X:
check cause stack trace and there should be Resources$NotFoundException like this:
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f0b0066
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:190)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2094)
at android.content.res.Resources.getLayout(Resources.java:1111)
at android.view.LayoutInflater.inflate(LayoutInflater.java:424)
Resource ID is actually exact integer from generated R.java file.
Find 0x7f0b0066 which will point to the xml file which could not be inflated(found).
In most cases that's because directory layout doesn't have this resource, but some layout-XXX has.
And solution is to put resource into all required directories. Or just at least into layout.
In my case i had
<android.support.design.widget.NavigationView...
and in app config:
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
So I changed the XML to:
com.google.android.material.navigation.NavigationView...
I had the same problem after upgrading the support library and none of the answers worked for me. Finally I solved downloading latest version of build tools and upgrading in build.gradle to buildToolsVersion "23.0.1"
One thing to double-check is that you have applied your theme correctly in your AndroidManifest.xml file. In my case, I had omitted the android:theme attribute. E.g:
<application ... android:theme="#style/Your.Theme.Here" ... >
BETTER I UPGRADED com.android.support:appcompat-v7:23.1.0
as #Ton said downgrade compile 'com.android.support:design:23.1.0'
BUT Why not to upgrade com.android.support:appcompat-v7:23.1.1
Final upgraded worked for me enjoy
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
So why to use older library. I think is now better to use both design and compact upgraded.
I was also having this same issue, after looking nearly 3 hours I find out that the problem was in my drawable_menu.xml file, it was wrongly written :D
This error can be caused due to reasons as mentioned below.
This problem will likely occur when the version of your appcompat library and design support library doesn't match.
Example of matching condition
compile 'com.android.support:appcompat-v7:24.2.0' // appcompat library
compile 'com.android.support:design:24.2.0' //design support library
If your theme file in styles have only these two,
<item name="colorPrimary">#4A0958</item>
<item name="colorPrimaryDark">#4A0958</item>
then add ColorAccent too. It should look somewhat like this.
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#4A0958</item>
<item name="colorPrimaryDark">#4A0958</item>
<item name="colorAccent">#4A0958</item>
</style>
It's weird but clean project and rebuild project worked for me.
I found solution...
if you used app:srcCompat change to android:src
this solution worked for me :)
I was facing this error in Xamarin. This was due to some files that were present in drawable-v21 folder. So I copied those files (probably icon files) to the drawable folder and the error was gone.
I created a state-list selector file item_bg_selector.xml in the drawable folder like this :
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true"
android:drawable="#drawable/item_background_selected" />
<item android:state_focused="true"
android:drawable="#drawable/item_background_selected" />
<item android:state_pressed="true"
android:drawable="#drawable/item_background_selected" />
<item android:drawable="#android:color/transparent"/>
</selector>
Then i define a style element
<style name="Item">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:background">#drawable/item_bg_selector</item>
</style>
Then I try to create an ImageButton like this :
<ImageButton style="#style/Item"
android:id="#id/btn_home"
android:src="#drawable/home_button" />
Eclipse keeps giving me the following error in the Event Details window :
Failed to parse file /path/to/projectdir/res/drawable/item_bg_selector.xml
The exception trace is given below :
org.xmlpull.v1.XmlPullParserException: Binary XML file line #16: <item> tag requires a 'drawable' attribute or child tag defining a drawable
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:167)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:728)
at com.android.layoutlib.bridge.impl.ResourceHelper.getDrawable(ResourceHelper.java:208)
at com.android.layoutlib.bridge.android.BridgeTypedArray.getDrawable(BridgeTypedArray.java:731)
at android.view.View.<init>(View.java:1885)
at android.widget.ImageView.<init>(ImageView.java:112)
at android.widget.ImageButton.<init>(ImageButton.java:85)
at android.widget.ImageButton.<init>(ImageButton.java:81)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at android.view.LayoutInflater.createView(LayoutInflater.java:500)
at com.android.layoutlib.bridge.android.BridgeInflater.onCreateView(BridgeInflater.java:84)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
at com.android.layoutlib.bridge.android.BridgeInflater.createViewFromTag(BridgeInflater.java:129)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
at android.view.LayoutInflater.inflate(LayoutInflater.java:296)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:279)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:318)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:325)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.RenderService.createRenderSession(RenderService.java:372)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.renderWithBridge(GraphicalEditorPart.java:1317)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.recomputeLayout(GraphicalEditorPart.java:1071)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.activated(GraphicalEditorPart.java:897)
at com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditor.pageChange(LayoutEditor.java:384)
at org.eclipse.ui.part.MultiPageEditorPart$2.widgetSelected(MultiPageEditorPart.java:290)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:234)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:3783)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1375)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1398)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1383)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1195)
at org.eclipse.swt.custom.CTabFolder.setSelection(CTabFolder.java:2743)
at org.eclipse.swt.custom.CTabFolder.onMouse(CTabFolder.java:1429)
at org.eclipse.swt.custom.CTabFolder$1.handleEvent(CTabFolder.java:257)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:3783)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1375)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1398)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1383)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1195)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3629)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3284)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2640)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2604)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2438)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:671)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:664)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:620)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:575)
at org.eclipse.equinox.launcher.Main.run(Main.java:1408)
Now, The question is where is the error? the drawables exist in the folder. tag has a drawable attribute. I have cross checked this close to 15 times and still I have not been able to find the problem. I believe it is a very simple problem(if any). Any work around to get over with this is also appreciated.
Addition :
Also, line 16 in item_bg_selector.xml corresponds to the third line from the top in the file I have posted. that is
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true"
line16 ----> android:drawable="#drawable/item_background_selected" />
The error has to do with the format of your xml, you are setting something like
android:background="#drawable/item_bg_selector"
What the error is telling you is that it should be like this
android:drawable="#drawable/item_bg_selector"
I've experienced the same Exception for a different problem.
I was trying to use a color selector for the View's android:background:
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/tab_background_selector" />
<!-- /res/color/tab_background_selector.xml -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/white" android:state_checked="true" />
<item android:color="#color/light_blue" />
</selector>
Moving the selector to the drawable folder and changing android:color to android:drawable solved the problem.
Also, the background definition in the Layout needs to be changed to android:background="#drawable/tab_background_selector"
Here is the final selector:
<!-- /res/drawable/tab_background_selector.xml -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/white" android:state_checked="true" />
<item android:drawable="#color/light_blue" />
</selector>
I had the same error and switching the order of the attributes (as it was suggested in the this answer to this other question) to have the drawable the first one solved the problem.
In your case would be switching:
<item android:state_selected="true"
android:drawable="#drawable/item_background_selected" />
to:
<item android:drawable="#drawable/item_background_selected"
android:state_selected="true" />
Finally, I got to know that its a problem with just ADT and it actually runs fine on the device. This corresponds to issue 21046.
similar to this answer, I need to make a drawable version of the color resource.
solution
instead of modifying the existing color state list file, craete a new drawable file
new_drawable_file.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#color/old_color_state_list" />
</shape>
then i updated the problematic usages of #color/old_color_state_list to #drawable/new_drawable_file.
background
in my styles.xml, i had overridden ?android:activatedBackgroundIndicator with my #color/old_color_state_list
<item name="android:activatedBackgroundIndicator">#color/old_color_state_list</item>
but the documentation for ?android:activatedBackgroundIndicator says it should be a drawable resource, not a color:
Drawable used as a background for activated items.
so, i updated my styles.xml to override ?android:activatedBackgroundIndicator with my #drawable/new_drawable_file drawable, instead.
<item name="android:activatedBackgroundIndicator">#drawable/new_drawable_file</item>
I also encountered the same issue.
I just restarted eclipse with -clean, and the did a project -> Clean on the project in question and the errors have gone away.
Restarting Eclipse and cleaning the project worked for me.
The same error occurs on the activity_main.xml file if there is an extra LinearLayout in the Activity. Removing this solves the issue.
Cleaning and other things do not help.
The drawable inside the file (a png) was corrupted. I just saved again the file and it worked.
I got it to work by copying the image right into the file system (Finder on Mac) rather than through Android Studio.
I had the problem because when renaming the selector for pre-lollipop devices, I forgot to rename the ripple with th e same name also in the drawable-v21 folder.
In my case I was applying color attribute to checkedIcon attribute, Instead
of chipIconTint, so replacing checkedIcon with chipIconTint in style solved
my problem.
Use
<item name="chipIconTint">#color/chip_text_color</item>
Instead of
<item name="checkedIcon">#color/chip_text_color</item>