Exception in Drawable.createFromResourceStream() — HTC ONLY?

前端 未结 3 1450
余生分开走
余生分开走 2021-01-06 12:44

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.NullPointe         


        
相关标签:
3条回答
  • 2021-01-06 12:59

    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 dummy Options objects and still maintain the default behaviour.

    So:

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

    Can anyone verify this on an HTC device?

    0 讨论(0)
  • 2021-01-06 13:04

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

    0 讨论(0)
  • 2021-01-06 13:09

    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);
    }
    

    This only works with files.

    0 讨论(0)
提交回复
热议问题