ResourcesNotFoundException when resource available (API 22 and 23 devices)

强颜欢笑 提交于 2019-12-22 00:23:33

问题


I get this crash only on API 22 and 23 devices.

(android.content.res.Resources$NotFoundException: File res/drawable/show_empty_state.xml from drawable resource ID #0x7f080156 at android.content.res.Resources.loadDrawableForCookie(Resources.java:2640) at android.content.res.Resources.loadDrawable(Resources.java:2540) at android.content.res.Resources.getDrawable(Resources.java:806) at android.content.Context.getDrawable(Context.java:458) at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:358) at com.myProj.utils.EmptyStateView.setImage(EmptyStateView.java:55) at com.myProj.tab_two.ShowFragment.onCreateView(ShowFragment.java:111) at android.support.v4.app.Fragment.performCreateView(Fragment.java:2261)

The resource is definitely there and it works fine on higher devices. The only recent change i did was replace a new vector image using SVG for show_empty_state. I did look at some other related questions. Could not find an answer so far. Any help is appreciated. Thanks.


回答1:


The crash was because the vector asset had gradient tag for <24 devices.

android:fillColor
Specifies the color used to fill the path. May be a color or, for SDK 24+, a color state list or a gradient color (See GradientColor and GradientColorItem). If this property is animated, any value set by the animation will override the original value. No path fill is drawn if this property is not specified.

Replacing the

<gradient android:endX="45300.0" android:endY="-86698.0"
       <android:startX="45300.0" android:startY="-3118.0" android:type="linear">
       <item android:color="#FF1AA186" android:offset="0.0"/>
       <item android:color="#FF23B899" android:offset="1.0"/>
 </gradient>

with

android:fillColor="#FF1AA186"

fixes it.

Better would be to replace the asset with a non-gradient one for <24 sdk.




回答2:


You need to be sure that inside path tag of your vector drawable you are using fill color as hexcode rather then any reference to color file.

For example:

You need to use

android:fillColor="#FFFFaa"

instead of

android:fillColor="@color/colorname"


来源:https://stackoverflow.com/questions/48688593/resourcesnotfoundexception-when-resource-available-api-22-and-23-devices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!