异常的Drawable.createFromResourceStream() - HTC而已? [英] Exception in Drawable.createFromResourceStream() -- HTC ONLY?

查看:763
本文介绍了异常的Drawable.createFromResourceStream() - HTC而已?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经发布了输入法(软键盘)的应用程序,我正在崩溃报告从 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)
    ...

这是我的呼吁Drawable.createFromResourceStream()

Here is my call to Drawable.createFromResourceStream()

drawable = Drawable.createFromResourceStream(context.getResources(), null, stream, null);

其中,上下文 InputMethodService 流的一个子类要么是的FileInputStream AssetInputStream 的(我都试过)。资源文件编译的 NinePatchDrawable 的。我已经证实该流不为空。

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.

要重复:这个错误只发生在特定的HTC手机(包括埃沃)运行各种版本的Andr​​oid操作系统的

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?

在此先感谢,

巴里

P.S。奇怪的是崩溃线465不在大跌方法的 BitmapFactory.de codeResourceStream()的任何版本的 BitmapFactory.java 的那么HTC必须使用修改$ C $℃。

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.

推荐答案

找到了一个解决这个问题,你可以用替换调用 Drawable.createFromResourceStream

Found a solution for this problem, you can replace the call to Drawable.createFromResourceStream with:

// set options to resize the image
Options opts = new BitmapFactory.Options();
opts.inDensity = 160;

Drawable drawable  = null;
Bitmap bm = BitmapFactory.decodeFile(file.getAbsolutePath(), opts);
if (bm != null) {
  drawable = new BitmapDrawable(context.getResources(), bm);
}

这仅适用于文件。

这篇关于异常的Drawable.createFromResourceStream() - HTC而已?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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