Exception in Drawable.createFromResourceStream () - HTC ONLY?

I released the IME application (soft keyboard) and I get crash reports from HTC phones . 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 subclass of InputMethodService and stream is FileInputStream or AssetInputStream (I tried both). A resource file is a compiled NinePatchDrawable file. I confirmed that the thread is not null.

Repeat: this error only occurs with some HTC phones (including Evo) with different versions of the Android OS.

Has anyone experienced this and / or knew how to fix it?

Thanks in advance,

Barry

PS It is strange that line 465 of the failure is not in the breakdown method of BitmapFactory.decodeResourceStream () in any version of BitmapFactory.java, therefore HTC must use a modified code.

+3
android android-assets nine-patch htc-android
source share
3 answers

Found a solution to 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); } 

This only works with files.

+4
source share

You can use Drawable.createFromStream () instead of Drawable.createFromResourceStream()

+1
source share

Have you tried to provide Drawable.createFromResourceStream full range of valid parameters? I looked at the Android code and you pass in both dummy TypedValue and dummy Options objects without any problems, and still retain the default behavior.

So:

  Options opts = new BitmapFactory.Options(); TypedValue dummy = new TypedValue(); Drawable d = Drawable.createFromResourceStream( mContext.getResources(), dummy, in, assetPath, opts); 

Can anyone confirm this on an HTC device?

0
source share

All Articles