Drawable.createFromResourceStream() 中的异常——仅限 HTC?
我发布了一个 IME(软键盘)应用程序,并且我仅从HTC 手机收到崩溃报告。这是堆栈跟踪:
java.lang.NullPointerException
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:465)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:666)
at com.comet.android.keyboard.util.Util.getBitmapDrawable(MyFile.java:416)
...
这是我对 Drawable.createFromResourceStream() 的调用
drawable = Drawable.createFromResourceStream(context.getResources(), null, stream, null);
,其中 context
是 InputMethodService 的子类,而 stream
是 >FileInputStream 或 AssetInputStream (我都尝试过)。资源文件是已编译的NinePatchDrawable。我已经确认流不为空。
重复一遍:此错误仅发生在运行不同版本 Android 操作系统的某些 HTC 手机(包括 Evo)上。
有没有人经历过这个和/或知道如何解决它?
预先感谢,
巴里
P.S.奇怪的是,崩溃行 465 不在 BitmapFactory.java 的任何版本中的崩溃方法 BitmapFactory.decodeResourceStream() 内,因此 HTC 必须使用修改后的代码。
I've released an IME (soft keyboard) app and I am getting crash reports from HTC phones only. Here is the stack trace:
java.lang.NullPointerException
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:465)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:666)
at com.comet.android.keyboard.util.Util.getBitmapDrawable(MyFile.java:416)
...
Here is my call to Drawable.createFromResourceStream()
drawable = Drawable.createFromResourceStream(context.getResources(), null, stream, null);
where context
a subclass of InputMethodService and stream
either is a FileInputStream or AssetInputStream (I've tried both). The resource file is a compiled NinePatchDrawable. I've confirmed that stream is not null.
To repeat: this bug only happens with certain HTC handsets (including the Evo) running various versions of Android OS.
Has anyone experienced this and/or know how to fix it?
Thanks in advance,
Barry
P.S. What is strange is that crash line 465 is not within crash method BitmapFactory.decodeResourceStream() in any version of BitmapFactory.java so HTC must be using modified code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
找到了此问题的解决方案,您可以将对
Drawable.createFromResourceStream
的调用替换为:这仅适用于文件。
Found a solution for this problem, you can replace the call to
Drawable.createFromResourceStream
with:This only works with files.
您可以只使用
Drawable.createFromStream ()
而不是Drawable.createFromResourceStream()
You can just use
Drawable.createFromStream ()
instead ofDrawable.createFromResourceStream()
您是否尝试过为
Drawable.createFromResourceStream
提供一整套有效参数?我查看了 Android 代码,您可以安全地传递虚拟
TypedValue
和虚拟Options
对象,并且仍然保持默认行为。那么:
有人可以在 HTC 设备上验证这一点吗?
Have you tried supplying
Drawable.createFromResourceStream
with a full set of valid params?I've looked at the Android code, and you saftely pass both a dummy
TypedValue
and a dummyOptions
objects and still maintain the default behaviour.So:
Can anyone verify this on an HTC device?