NotFoundException and FileNotFoundException when running an application on Android 1.5

I am trying to execute a backport android 1.6+ application for android 1.5.

Following the guidelines here:

... I did the following:

  • Change AndroidManifest.xml to set minSdkVersion to 3
  • Move all my files that were previously in drawable-mdpi / to drawable /
  • Rename drawable-hdpi / to drawable-hdpi-v4 /

It seems to me that this should ensure that 1.5 devices use files with the ability to draw / while 1.6 and later devices use files in drawable / and drawable-hdpi-v4 /, if necessary. The drawable / and drawable-hdpi-v4 / directories are the only directories available in my res folder.

However, after compiling, installing and running the resulting binary file on emulator 1.5, I get the following error:

E/AndroidRuntime( 1096): Caused by: java.lang.reflect.InvocationTargetException E/AndroidRuntime( 1096): at android.widget.ImageView.<init>(ImageView.java:103) E/AndroidRuntime( 1096): at java.lang.reflect.Constructor.constructNative(Native Method) E/AndroidRuntime( 1096): at java.lang.reflect.Constructor.newInstance(Constructor.java:446) E/AndroidRuntime( 1096): at android.view.LayoutInflater.createView(LayoutInflater.java:499) E/AndroidRuntime( 1096): ... 26 more E/AndroidRuntime( 1096): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/bg.png from drawable resource ID #0x7f02002e E/AndroidRuntime( 1096): at android.content.res.Resources.loadDrawable(Resources.java:1641) E/AndroidRuntime( 1096): at android.content.res.TypedArray.getDrawable(TypedArray.java:548) E/AndroidRuntime( 1096): at android.widget.ImageView.<init>(ImageView.java:113) E/AndroidRuntime( 1096): ... 30 more E/AndroidRuntime( 1096): Caused by: java.io.FileNotFoundException: res/drawable/bg.png E/AndroidRuntime( 1096): at android.content.res.AssetManager.openNonAssetNative(Native Method) E/AndroidRuntime( 1096): at android.content.res.AssetManager.openNonAsset(AssetManager.java:392) E/AndroidRuntime( 1096): at android.content.res.Resources.loadDrawable(Resources.java:1634) E/AndroidRuntime( 1096): ... 32 more 

For reasons that I don’t understand, 1.5 devices cannot see the bg.png image file, a version of which is in the drawable / and drawable-hdpi-v4 / directories.

Running the same binaries works fine on 1.6.

Why won't it be visible that 1.5 devices display my res / drawable / bg.png image with this setting?

UPDATE: As described in Providing Screen Resource Compatibility for Android 1.5 , I use the Android SDK r6 and put my mdpi resources in the drawable / directory. In addition, I checked that the problem is not isolated from bg.png. If I remove the broken link selected in my xml, the application breaks into the next and each subsequent graphic during setContentView ().

+2
source share
3 answers

Success!!!

The problem was that I had one resource foo.png in drawable-hdpi-v4 /, which was not in the drawable / directory. When I referenced the R.drawable.foo file from my layout file, the emulator 1.5 therefore could not find a suitable resource for this identifier. Because of this, it was difficult to detect that the error did not occur immediately when linking to foo.png, but rather to the NEXT error referenced by bg.png. Google has confirmed that this is a bug.

Adding the mdpi version of foo.png to the drawable / directory fixes the problem.

+4
source

I ran into the same problem a few days ago. And the only solution I found was to create a new project from scratch and add source and res files to them. This will definitely fix the problem.

0
source

If you build your project using Android 1.6 with minSDKVesrion set to 3, you can only create 3 drawable-hdpi, drawable-mdpi, drawable-ldpi folders. I recreated your problem in my project, and when I changed the structure of the Res folders, it started working fine. You can try it (there is a problem with Android 1.5 that you know about. Many 1.5 mdpi devices are extracting resources from the drawable-ldpi folder.)

0
source

All Articles