Webveiw 的 WebViewContentsClientAdapter 获取bitmap 宽高 时 bitmap 空指针

冰冰的冻结
  • 519

java.lang.NullPointerException

Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference

解析原始
1 com.android.webview.chromium.WebViewContentsClientAdapter.getDefaultVideoPoster(WebViewContentsClientAdapter.java:596)
2 org.chromium.android_webview.DefaultVideoPosterRequestHandler$$Lambda$0.run(Unknown Source:2)
3 android.os.Handler.handleCallback(Handler.java:808)
4 android.os.Handler.dispatchMessage(Handler.java:101)
5 android.os.Looper.loop(Looper.java:166)
6 android.app.ActivityThread.main(ActivityThread.java:7425)
7 java.lang.reflect.Method.invoke(Native Method)
8 com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
9 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)

回复
阅读 5.1k
2 个回答
YuNnY
  • 1
新手上路,请多包涵

Here's a workaround for the problem:

Add to your MainActivity:

@Override
public AssetManager getAssets() {
    return getResources().getAssets();
}

we know what's causing this, but fixing it is non-trivial at this point in M development. The workaround should be ok though.

chrome 官方的规避方案
https://bugs.chromium.org/p/c...

宣传栏