日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

android webview 报错,Android WebView 5.x 系统下 Resources$NotFoundException异常处理

發布時間:2025/3/12 Android 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android webview 报错,Android WebView 5.x 系统下 Resources$NotFoundException异常处理 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

最近線上后臺發現一個崩潰問題,在Android5.x上,創建webview時會發生carsh,報錯信息:

Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x2040003

at android.content.res.Resources.getText(Resources.java:318)

at android.content.res.VivoResources.getText(VivoResources.java:123)

at android.content.res.Resources.getString(Resources.java:404)

at com.android.org.chromium.content.browser.ContentViewCore.setContainerView(ContentViewCore.java:694)

at com.android.org.chromium.content.browser.ContentViewCore.initialize(ContentViewCore.java:618)

at com.android.org.chromium.android_webview.AwContents.createAndInitializeContentViewCore(AwContents.java:631)

at com.android.org.chromium.android_webview.AwContents.setNewAwContents(AwContents.java:780)

at com.android.org.chromium.android_webview.AwContents.(AwContents.java:619)

at com.android.org.chromium.android_webview.AwContents.(AwContents.java:556)

at com.android.webview.chromium.WebViewChromium.initForReal(WebViewChromium.java:312)

at com.android.webview.chromium.WebViewChromium.access$100(WebViewChromium.java:96)

at com.android.webview.chromium.WebViewChromium$1.run(WebViewChromium.java:264)

在大部分的vivo 5.x系統下會出現問題,非5.x系統不會出現。

解決辦法一

在Android5.x上通過解決自定義WebView

網上大部分都是這種方式解決的。

public class LollipopFixedWebView extends WebView {

public LollipopFixedWebView(Context context) {

super(getFixedContext(context));

}

public LollipopFixedWebView(Context context, AttributeSet attrs) {

super(getFixedContext(context), attrs);

}

public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr) {

super(getFixedContext(context), attrs, defStyleAttr);

}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)

public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {

super(getFixedContext(context), attrs, defStyleAttr, defStyleRes);

}

public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr, boolean privateBrowsing) {

super(getFixedContext(context), attrs, defStyleAttr, privateBrowsing);

}

public static Context getFixedContext(Context context) {

if (Build.VERSION.SDK_INT >= 21 && Build.VERSION.SDK_INT < 23) // Android Lollipop 5.0 & 5.1

return context.createConfigurationContext(new Configuration());

return context;

}

}

主要核心方法是getFixedContext(context),根據版本號配置不同的context.

解決方法二

如果項目中使用"androidx.appcompat:appcompat:1.1.0" ,替換為"androidx.appcompat:appcompat:1.0.2"

1.1.0版本webview在Android5.x上有問題,恢復到1.0.2之后確實解決了此問題,目前沒有具體追蹤,后續會跟上。

"androidx.appcompat:appcompat:1.1.0"發布時間:2019/09/05,到現在更新一個月時間~

"androidx.appcompat:appcompat:1.0.2"發布時間:2018/10/07,到現在更新一年時間~

為了保證項目穩定,build gradle依賴更新時間要適當。

最后,希望此篇博客對大家有所幫助,歡迎提出問題及建議共同探討,如有興趣可以關注我的博客,謝謝!

總結

以上是生活随笔為你收集整理的android webview 报错,Android WebView 5.x 系统下 Resources$NotFoundException异常处理的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。