4

Actually i have openned a live stream url within a android webview and getting a issue of null pointer of bitmap.getwidth(). so my question is it is need to fix from android app or from the server side? Not getting the line no or other things to fix it. any idea

Fatal Exception: 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:1142)
       at org.chromium.android_webview.DefaultVideoPosterRequestHandler$1.run(DefaultVideoPosterRequestHandler.java:39)
       at android.os.Handler.handleCallback(Handler.java:739)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:135)
       at android.app.ActivityThread.main(ActivityThread.java:5254)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:697)
Anas Mehar
  • 2,739
  • 14
  • 25
AndroidDev
  • 51
  • 4
  • 1
    Here is also answer: https://stackoverflow.com/questions/46886701/webview-crashes-when-displaying-a-youtube-video/47087335 – yozhik Feb 12 '20 at 10:02

1 Answers1

3

Add below code to your CustomChromeClient;

@Nullable
@Override
public Bitmap getDefaultVideoPoster() {
    if (super.getDefaultVideoPoster() == null) {
        return BitmapFactory.decodeResource(context.getResources(),
                R.drawable.ic_launcher);
    } else {
        return super.getDefaultVideoPoster();
    }
}

it should work with this workaround:

In Kotlin:

override fun getAssets(): AssetManager {
    return resources.assets
}

In Java:

@Override
public AssetManager getAssets() {
    return getResources().getAssets();
} 
Karan Sethi
  • 223
  • 1
  • 14