尝试使用webview打开视频时出现以下错误。奇怪的是,相同的代码适用于不同的项目。这只发生在Android 8.0 OREO
上 java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mobisoft.flyco, PID: 11628
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
at com.android.webview.chromium.Ap.getDefaultVideoPoster(WebViewContentsClientAdapter.java:585)
at org.chromium.android_webview.DefaultVideoPosterRequestHandler$$Lambda$0.run(Unknown Source: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:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
CODE SNIPPET
webView = (WebView) findViewById(R.id.webView);
WebSettings
webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.setWebChromeClient(new WebChromeClient());
webView.loadUrl("youtube.com/watch?v=D7LB-QPxH9c");