【问题标题】:ResourcesNotFoundException on some devices某些设备上的 ResourceNotFoundException
【发布时间】:2012-09-08 17:40:25
【问题描述】:

我最近收到了关于我的应用的崩溃报告。它是这样说的:

android.content.res.Resources$NotFoundException: File res/drawable-xhdpi/bg.png from drawable resource ID #0x7f020005

然后是这个:

Caused by: java.lang.IllegalArgumentException: width and height must be > 0
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:477)
at android.graphics.Bitmap.createBitmap(Bitmap.java:444)
at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:349)
at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:601)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:576)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:439)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
at android.content.res.Resources.loadDrawable(Resources.java:1709)

我在多台设备上测试了我的应用,但没有一台设备崩溃。 根据我的应用程序用户的说法,这个错误似乎出现在三星 Galaxy y pro 上 我真的不知道该怎么办......

【问题讨论】:

  • 您的哪些文件夹有 bg.png?
  • 只有drawable-xhdpi,要不要放到所有drawable文件夹里?
  • 我在某个应用上看到过类似的崩溃报告。有问题的设备也是三星 Galaxy Y。我无法重现该问题。
  • 我遇到了同样的问题。原因可能是一个四舍五入的问题。我的图像只有 1 像素高,因此设备可以适当地将其缩放到 0.5 像素以下,并最终创建一个高度为 0 像素的位图。

标签: android bitmap crash


【解决方案1】:

我发现出了什么问题。 Galaxy Y 的屏幕很小,分辨率也很低。而且我认为这个设备不知道什么是 xhdpi 文件夹,所以你应该把你的 drawable 放到所有文件夹中......

希望,它会有所帮助:)

【讨论】:

  • 至少你可以将所有其他资源的drawable放在drawable文件夹或drawable-nodpi中。系统在找不到所需资源时应查看这些文件夹。
猜你喜欢
  • 2013-02-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多