Cannot find ColorStateList from resource id with resource only on Android Nougat

I found this error in my Crashlytics and it seems to only crash for users with the Android Nougat preview version.

Failure to load the application at startup (main activity).

Stacktrace

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.my.domain/com.my.domain.activities.MainActivity}: android.content.res.Resources$NotFoundException: Can't find ColorStateList from drawable resource ID #0x7f020057 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6077) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) Caused by android.content.res.Resources$NotFoundException: Can't find ColorStateList from drawable resource ID #0x7f020057 at android.content.res.ResourcesImpl.loadColorStateList(ResourcesImpl.java:840) at android.content.res.Resources.loadColorStateList(Resources.java:998) at android.content.res.TypedArray.getColor(TypedArray.java:447) at android.app.Activity.onApplyThemeResource(Activity.java:4039) at android.view.ContextThemeWrapper.initializeTheme(ContextThemeWrapper.java:198) at android.view.ContextThemeWrapper.setTheme(ContextThemeWrapper.java:140) at android.app.Activity.setTheme(Activity.java:4009) at android.support.v7.app.AppCompatActivity.setTheme(AppCompatActivity.java:90) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2592) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6077) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 

It looks like Android Nougat no longer supports some of the system colors that I use in my application? But I don’t know exactly how to fix it.

Edit

So, I found the resource with identifier 0x7f020057 in the R file, and this is it:

public static final int background_splash_gradient = 0x7f020057;

I checked where I use it, and here it is:

 <style name="StartingWindowTheme" parent="AppTheme"> <item name="android:windowBackground">@drawable/background_splash_gradient</item> <item name="android:colorBackground">@drawable/background_splash_gradient</item> </style> 

And this is background_splash_gradiend xml file:

 <shape xmlns:android="http://schemas.android.com/apk/res/android"> <gradient android:angle="135" android:endColor="#00d49e" android:startColor="#00bcd4"/> </shape> 

I still don’t know why this causes problems in Nougat. I tried to remove the "StartWindowTheme" style and the application now works, it will no longer work. But I need a better fix than that.

Edit 2

So, I tried to delete this line:

 <item name="android:colorBackground">@drawable/background_splash_gradient</item> 

And it works. android:colorBackground seems to be the problem.

TEMPORARY CORRECTION

Since the problem in the line mentioned above is only on Nougat, I created the values-v24 and deleted the line there. Now the application is working on Nougat, but I would appreciate a better solution.

+7
android android-7.0-nougat
source share
2 answers

I found where the problem is and how to fix it. Here is the solution, I will keep it simple.

This line caused the problem:

 <item name="android:colorBackground">@drawable/background_splash_gradient</item> 

Turns out you can't set drawable as colorBackground in XML, so it works after deleting this line.

The reason this only happened in Nougat is because it is possible in earlier versions.

+2
source share

It turns out that according to Android's problem tracking , this works as intended.

android:colorBackground expects color is not valid.

0
source share

All Articles