错误描述
androidx在Android 5.1部分机型报Resources$NotFoundException
错误详细信息
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.<init>(AwContents.java:619)
at com.android.org.chromium.android_webview.AwContents.<init>(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)
at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue.drainQueue(WebViewChromium.java:123)
at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue$1.run(WebViewChromium.java:110)
at com.android.org.chromium.base.ThreadUtils.runOnUiThread(ThreadUtils.java:144)
at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue.addTask(WebViewChromium.java:107)
at com.android.webview.chromium.WebViewChromium.init(WebViewChromium.java:261)
at android.webkit.WebView.<init>(WebView.java:554)
at android.webkit.WebView.<init>(WebView.java:489)
at com.XXX.app.view.webview.view.XXXWebView.<init>(XXXWebView.java)
at com.XXX.app.view.webview.view.XXXWebView.<init>(XXXWebView.java)
at com.XXX.app.view.webview.view.XXXWebView.<init>(XXXWebView.java)
at com.XXX.app.view.webview.fragment.WebViewFragment.c(WebViewFragment.java)
at androidx.fragment.app.Fragment.h(Fragment.java)
at androidx.fragment.app.FragmentManagerImpl.a(FragmentManagerImpl.java)
at androidx.fragment.app.FragmentTransition.a(FragmentTransition.java)
at androidx.fragment.app.FragmentTransition.a(FragmentTransition.java)
at androidx.fragment.app.FragmentTransition.a(FragmentTransition.java)
at androidx.fragment.app.FragmentManagerImpl.transitToStyleIndex(FragmentManagerImpl.java)
at androidx.fragment.app.FragmentManagerImpl.c(FragmentManagerImpl.java)
at androidx.fragment.app.FragmentManagerImpl.transitToStyleIndex(FragmentManagerImpl.java)
at androidx.fragment.app.BackStackRecord.c(BackStackRecord.java)
at com.XXX.app.view.webview.activity.SimpleWebViewActivity.onCreate(SimpleWebViewActivity.java)
at android.app.Activity.performCreate(Activity.java:6083)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1115)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2357)
... 10 more
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.<init>(AwContents.java:619)
at com.android.org.chromium.android_webview.AwContents.<init>(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)
at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue.drainQueue(WebViewChromium.java:123)
at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue$1.run(WebViewChromium.java:110)
at com.android.org.chromium.base.ThreadUtils.runOnUiThread(ThreadUtils.java:144)
at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue.addTask(WebViewChromium.java:107)
at com.android.webview.chromium.WebViewChromium.init(WebViewChromium.java:261)
at android.webkit.WebView.<init>(WebView.java:554)
at android.webkit.WebView.<init>(WebView.java:489)
at com.XXX.app.view.webview.view.XXXWebView.<init>(XXXWebView.java)
at com.XXX.app.view.webview.view.XXXWebView.<init>(XXXWebView.java)
at com.XXX.app.view.webview.view.XXXWebView.<init>(XXXWebView.java)
at com.XXX.app.view.webview.fragment.WebViewFragment.c(WebViewFragment.java)
at androidx.fragment.app.Fragment.h(Fragment.java)
at androidx.fragment.app.FragmentManagerImpl.a(FragmentManagerImpl.java)
at androidx.fragment.app.FragmentTransition.a(FragmentTransition.java)
at androidx.fragment.app.FragmentTransition.a(FragmentTransition.java)
at androidx.fragment.app.FragmentTransition.a(FragmentTransition.java)
at androidx.fragment.app.FragmentManagerImpl.transitToStyleIndex(FragmentManagerImpl.java)
at androidx.fragment.app.FragmentManagerImpl.c(FragmentManagerImpl.java)
at androidx.fragment.app.FragmentManagerImpl.transitToStyleIndex(FragmentManagerImpl.java)
at androidx.fragment.app.BackStackRecord.c(BackStackRecord.java)
at com.XXX.app.view.webview.activity.SimpleWebViewActivity.onCreate(SimpleWebViewActivity.java)
at android.app.Activity.performCreate(Activity.java:6083)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1115)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2357)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2466)
at android.app.ActivityThread.access$900(ActivityThread.java:175)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1369)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5418)
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:1037)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
解决办法
自定义WebView,替换初始化的context
public WebView(Context context) {
this(context, null);
}
public WebView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public WebView(Context context, AttributeSet attrs, int defStyleAttr) {
super(getFixedContext(context), attrs, defStyleAttr, defStyleAttr);
}
private static Context getFixedContext(Context context) {
// Android Lollipop 5.0 & 5.1
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
return context.createConfigurationContext(new Configuration());
}
return context;
}
网友评论