user291701
user291701

Reputation: 39681

Resources$NotFoundException exception for drawable - but it does exist?

I'm starting to see an odd set of stack traces from the marketplace crash reports interface. I'm being told a drawable resource does not exist. The xml in question:

<ImageView
  android:layout_width="13dip"
  android:layout_height="12dip"
  android:src="@drawable/foo"
  />

causing:

java.lang.RuntimeException: 
    Unable to start activity ComponentInfo{com.me.app/com.me.app.MyActivity}: 
    android.view.InflateException: Binary XML file line #51: 
    Error inflating class <unknown>
...
Caused by: android.content.res.Resources$NotFoundException: 
  File res/drawable-hdpi/foo.png from drawable resource ID #0x7f020166
  at android.content.res.Resources.loadDrawable(Resources.java:1732)
  at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
  at android.widget.ImageView.<init>(ImageView.java:118)
  at android.widget.ImageView.<init>(ImageView.java:108)
Caused by: java.io.FileNotFoundException: 
  res/drawable-hdpi/foo.png
  at android.content.res.AssetManager.openNonAssetNative(Native Method)
  at android.content.res.AssetManager.openNonAsset(AssetManager.java:417)
  at android.content.res.Resources.loadDrawable(Resources.java:1724)

Now "foo.png" exists in both my "drawable" and "drawable-hdpi" folders. I haven't touched either of these drawables in ages - not sure why this error started popping up? Happening on a range of devices, Droids, Nexus Ones, etc.

Thanks

Upvotes: 8

Views: 2497

Answers (2)

Farhad
Farhad

Reputation: 12986

You can try the following methods :

1- If you're developing in Eclipse, try "Project Clean" from debug menu. If you're in Intellij, try to "Build" the project.

2- Delete and readd the foo.png resource. after deleting, try to regenerate the R and then readd.

3- Rename the foo.png to something else and see how it works.

4- Try deleting the R file, because it gets generated automatically and may solve your problem

As far as I know, the problem is with the R file of your project.

Upvotes: 0

user3647834
user3647834

Reputation: 33

Try by placing foo.png in other drawable folder i.e. mdpi, xhdpi and xxhdpi also. May be it can help.

Upvotes: 3

Related Questions