I'm working on an Android app which is now in production, and am occasionally seeing exceptions (reported via airbrake) with stuff like this:
[1.0.4] java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mycompany.android/com.mycompany.android.activities.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class <unknown>
... cut lots of stuff ...
### CAUSED BY ###: java.io.FileNotFoundException: res/drawable-hdpi/tab_active.9.png:
AssetManager.java:-2:in `android.content.res.AssetManager.openNonAssetNative'
AssetManager.java:406:in `android.content.res.AssetManager.openNonAsset'
Resources.java:1706:in `android.content.res.Resources.loadDrawable'
... cut lots more stuff ...
In testing, this view definitely worked on multiple HDPI devices, so that resource was fine there. Before building the final APK, I did a full clean/rebuild, and of course sent the APK out for internal testing. The fact that I get 1-2 exceptions like this per version instead of 10,000 would indicate that this resource is definitely packaged correctly for most users.
I'm completely stumped and unsure why it wouldn't load on certain phones. Has anyone seen something like this in their apps?
I never did track down the exact cause of this problem, but based on my experience developing the app in question I believe it was caused by hitting the memory limit for the activity. After your activity runs out of memory, it seems that all sorts of strange errors can happen, including stuff like this.
When I made other improvements to the app's memory management (particularly by using
SoftReference
with Bitmaps), these type of exceptions starting appearing less frequently.I guess, this devices are running Android 1.5
From the Docs on "Providing the Best Device Compatibility with Resources":
Since you are using the
-hdpi
-qualifier, this might be the problem because those where introduced in Android 1.6 (API-Level 4) and are therefore not available under Android 1.5See this topic: Drawable-hdpi, Drawable-mdpi, Drawable-ldpi Android
So, providing some fallback-drawbale resources in the
res/drawable
-folder might solve your issue.There seams to be a Bug based on my original idea which is described here: NotFoundException and FileNotFoundException when running app on Android 1.5
It seams that the error is thrown for the next resource. So be sure to provide fallback's for every drawable in the
res/drawable
-folder.This addresses Android 1.5, I'm not sure if this is still a problem in Android 2.3, but it seams that different manufactures handle those things different.