NotFoundException和FileNotFoundException异常在Android 1.5上运行的应用程序时, [英] NotFoundException and FileNotFoundException when running app on Android 1.5

查看:342
本文介绍了NotFoundException和FileNotFoundException异常在Android 1.5上运行的应用程序时,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的backport一个Android 1.6+应用程序到Android 1.5。

I'm trying to backport an android 1.6+ application to android 1.5.

下面继意见...

  • http://comments.gmane.org/gmane.comp。 handhelds.android.devel / 97051
  • <一个href="http://groups.google.com/group/android-developers/browse_thread/thread/ff22f6e42a4a46d2/4201a20aaa23069d" rel="nofollow">http://groups.google.com/group/android-developers/browse_thread/thread/ff22f6e42a4a46d2/4201a20aaa23069d
  • <一个href="http://stackoverflow.com/questions/2923823/android-2-2-sdk-breaks-compatibility-with-older-phones">http://stackoverflow.com/questions/2923823/android-2-2-sdk-breaks-compatibility-with-older-phones
  • <一个href="http://developer.android.com/intl/fr/guide/topics/resources/providing-resources.html#ScreenCompatibility" rel="nofollow">http://developer.android.com/intl/fr/guide/topics/resources/providing-resources.html#ScreenCompatibility
  • http://comments.gmane.org/gmane.comp.handhelds.android.devel/97051
  • http://groups.google.com/group/android-developers/browse_thread/thread/ff22f6e42a4a46d2/4201a20aaa23069d
  • http://stackoverflow.com/questions/2923823/android-2-2-sdk-breaks-compatibility-with-older-phones
  • http://developer.android.com/intl/fr/guide/topics/resources/providing-resources.html#ScreenCompatibility

...我也做了以下内容:

... I have done the following:

  1. 修改AndroidManifest.xml中设置的minSdkVersion 3
  2. 将我的所有文件都pviously $ P $的绘制,MDPI /到可绘制/
  3. 重命名绘制,华电国际/到可绘制-HDPI-V4 /

在我看来,这应该确保1.5设备使用的文件绘制/时1.6和更高版本的设备使用绘制的文件/文件和绘制-HDPI-V4 /合适。可绘制/和绘制-HDPI-V4 /目录是在我的资源文件夹中的唯一可绘制目录。

It seems to me that this should ensure that 1.5 devices use the files in drawable/ while 1.6 and later devices use the files in drawable/ and drawable-hdpi-v4/ as appropriate. The drawable/ and drawable-hdpi-v4/ directories are the only drawable directories in my res folder.

不过,我编译后,安装,并在1.5模拟器运行生成的二进制文件,我得到以下错误:

However, after I compile, install, and run the resulting binary on the 1.5 emulator, 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

有关原因,我就不明白了,1.5的设备都没有能够看到bg.png图像文件,一个版本,这是在这两个绘制/和绘制-HDPI-V4 /目录。

For reasons I don't understand, 1.5 devices are not able to see the bg.png image file, a version of which is in both the drawable/ and drawable-hdpi-v4/ directories.

运行相同的二进制工作正常1.6。

Running the same binary works fine on 1.6.

为什么不1.5设备看到我的RES /绘制/ bg.png图像与此设置?

Why won't 1.5 devices see my res/drawable/bg.png image with this setup?

更新:作为<一个描述href="http://developer.android.com/intl/fr/guide/topics/resources/providing-resources.html#ScreenCompatibility"相对=nofollow>为Android 1.5 提供了屏幕资源的兼容性,我使用的是Android SDK中R6,并把我的MDPI资源,在绘制/目录。此外,我已经验证了这个问题不是孤立的,以bg.png。如果我删除提及破绘制在我的XML,就下和的setContentView期间,每次随后的图形应用程序中断()。

UPDATE: As described in Providing screen resource compatibility for Android 1.5, I'm using Android SDK r6 and have put my mdpi resources in the drawable/ directory. Also, I've verified that the problem isn't isolated to bg.png. If I remove the reference to the broken drawable in my xml, the app breaks on the next and each subsequent graphic during setContentView().

推荐答案

成功!

问题是,我在绘制-HDPI-V4 1 foo.png资源/这不是present在绘制/目录。当我引用R.drawable.foo从我的布局文件,1.5模拟器,因此没能找到一个合适的资源的ID。是什么让这么难以追查的是,错误并没有立即引用foo.png时发生的,而是错误是扔在引用的下一个资源,这是bg.png。谷歌已经确认这是一个错误。

The problem was that I had one foo.png resource in drawable-hdpi-v4/ that was not present in the drawable/ directory. When I referenced R.drawable.foo from my layout file, the 1.5 emulator was therefore not able to find a suitable resource for that id. What made it so difficult to track down was that the error didn't happen immediately when referencing foo.png, but rather the error was thrown on the NEXT resource referenced, which was bg.png. Google has confirmed this is a bug.

添加foo.png的MDPI版本可绘制/目录下解决了问题。

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

这篇关于NotFoundException和FileNotFoundException异常在Android 1.5上运行的应用程序时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆