Reputation: 392
I get app crash with Resources$NotFoundException emulating the app on version 4.4.4 and lower. On higher Android version everything works fine. This is the code:
image1.setImageResource(getResources().getIdentifier(test_image,
"drawable", getResources().getString(R.string.app_package)));
Why is this happening and how to solve this?
Error log:
android.content.res.Resources$NotFoundException: Resource ID #0x7f020090
at android.content.res.Resources.getValue(Resources.java:1123)
at android.support.v7.widget.ResourcesWrapper.getValue(ResourcesWrapper.java:204)
at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:327)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:192)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:185)
at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100)
at android.support.v7.widget.AppCompatImageHelper.setImageResource(AppCompatImageHelper.java:69)
at android.support.v7.widget.AppCompatImageView.setImageResource(AppCompatImageView.java:78)
Upvotes: 2
Views: 2415
Reputation: 101
In case somebody comes across this thread like me when searching for a solution for this problem: Check if any of your resources are in version-dependent drawable folders, like src/main/res/drawable-v21. If so, move these to /main/res/drawable and rebuild your APK.
Upvotes: 0
Reputation: 46
If XML:
Use app:srcCompat
for ImageView and app:drawableEndCompat
for Textview drawable.
Upvotes: 2
Reputation: 1642
I had similar issue where I was using vector drawable for a textview drawableStart. Not sure why it was crashing with Resources$NotFoundException
but I solved it by creating another vector drawable and wrapping the other one in a layer-list like so
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Note to future self: Need to wrap ic_nav_setting here. Was crashing on 4.4.1 without it-->
<item android:drawable="@drawable/ic_nav_setting"/>
</layer-list>
I hope this can help someone facing similar issue later
Upvotes: 0
Reputation: 572
does drawable folders contain a drawable with test_image
value ?
Upvotes: 0
Reputation: 135
Try following this: Why getDrawable() doesn't work on some Android devices?
Try inserting before getResources "ContextCompat".
Like this:
ContextCompat.getDrawable(Context context, int id)
Upvotes: 0