7

After updating to 8.0 we get a crash so far we haven't seen before:

java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
                                                                 at com.android.webview.chromium.WebViewContentsClientAdapter.getDefaultVideoPoster(WebViewContentsClientAdapter.java:536)
                                                                 at org.chromium.android_webview.DefaultVideoPosterRequestHandler$1.run(DefaultVideoPosterRequestHandler.java:2)
                                                                 at android.os.Handler.handleCallback(Handler.java:789)
                                                                 at android.os.Handler.dispatchMessage(Handler.java:98)
                                                                 at android.os.Looper.loop(Looper.java:164)
                                                                 at android.app.ActivityThread.main(ActivityThread.java:6541)
                                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                                 at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

Is this a bug in Chrome?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
breakline
  • 5,776
  • 8
  • 45
  • 84

2 Answers2

16

Thanks to @breakline's answer, I got this issue worked around! Thanks! But instead of using decoding a bitmap, I just create an empty one and return that:

    setWebChromeClient(new WebChromeClient() {
        @Override
        public Bitmap getDefaultVideoPoster() {
            return Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888);
        }
    });
Boy
  • 7,010
  • 4
  • 54
  • 68
11

Anyone still wondering instead of downvoting here is the actual fix to this. Since I spent quite some time on this I will post it here.

You need to add the following to your WebChromeClient:

webview.setWebChromeClient(new WebChromeClient() {
        @Override
        public Bitmap getDefaultVideoPoster() {
            Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.black);
            return icon;
        }
    });

Any drawable is fine as long as it is an actual PNG file. If you use a drawable/xml you still get an exception.

breakline
  • 5,776
  • 8
  • 45
  • 84
  • WOW! you saved me!! +1 – avisper Nov 22 '17 at 14:27
  • 1
    I faced with this issue on Chinese phone OUKITEL K10000 that is quite rare among others in my target audience (TA). One of the possible causes is a customization of AOSP, but often it impacts video, sound or network layers. In my case, my users shouldn't work with video at all. – Gleichmut Feb 05 '21 at 11:56