Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
237 views
in Technique[技术] by (71.8m points)

java - android.view.InflateException Error inflating class android.webkit.WebView

In Lollipop (API 22) every time in my application I show a webview the application crashes. I have multiple crashes in my android developer console related to this event.

No need to say that it works on Android 4, 6 and 7.

Reading the stack trace (posted at the end of this post), something bugs me

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

I searched in the generated R.java without any luck, obviously because the ID does not exists, but it was worth a try.

Googling around the problem seems to be related to how lollipop handles the webview. I started a fresh AVD with lollipop based on a device I found on the crash reporter in GDC, and I can reproduce the problem.


Full stack trace:

android.view.InflateException: Binary XML file line #7: Error inflating class android.webkit.WebView
                  at android.view.LayoutInflater.createView(LayoutInflater.java:633)
                  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
                  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
                  at it.artecoop.ibreviary.WebViewFragment.onCreateView(WebViewFragment.java:67)
                  at android.support.v4.app.Fragment.performCreateView(Fragment.java:2087)
                  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1113)
                  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1295)
                  at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:801)
                  at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1682)
                  at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:541)
                  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(Native Method)
                  at java.lang.reflect.Method.invoke(Method.java:372)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
               Caused by: java.lang.reflect.InvocationTargetException
                  at java.lang.reflect.Constructor.newInstance(Native Method)
                  at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
                  at android.view.LayoutInflater.createView(LayoutInflater.java:607)
                  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)?
                  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)?
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)?
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)?
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:504)?
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:414)?
                  at it.artecoop.ibreviary.WebViewFragment.onCreateView(WebViewFragment.java:67)?
                  at android.support.v4.app.Fragment.performCreateView(Fragment.java:2087)?
                  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1113)?
                  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1295)?
                  at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:801)?
                  at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1682)?
                  at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:541)?
                  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(Native Method)?
                  at java.lang.reflect.Method.invoke(Method.java:372)?
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)?
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)?
               Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x2040003
                  at android.content.res.Resources.getText(Resources.java:299)
                  at android.content.res.Resources.getString(Resources.java:385)
                  at com.android.org.chromium.content.browser.ContentViewCore.setContainerView(ContentViewCore.java:684)
                  at com.android.org.chromium.content.browser.ContentViewCore.initialize(ContentViewCore.java:608)
                  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:311)
                  at com.android.webview.chromium.WebViewChromium.access$100(WebViewChromium.java:96)
                  at com.android.webview.chromium.WebViewChromium$1.run(WebViewChromium.java:263)
                  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:260)
                  at android.webkit.WebView.<init>(WebView.java:554)
                  at android.webkit.WebView.<init>(WebView.java:489)
                  at android.webkit.WebView.<init>(WebView.java:472)
                  at android.webkit.WebView.<init>(WebView.java:459)
                  at java.lang.reflect.Constructor.newInstance(Native Method)?
                  at java.lang.reflect.Constructor.newInstance(Constructor.java:288)?
                  at android.view.LayoutInflater.createView(LayoutInflater.java:607)?
                  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)?
                  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)?
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)?
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)?
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:504)?
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:414)?
                  at it.artecoop.ibreviary.WebViewFragment.onCreateView(WebViewFragment.java:67)?
                  at android.support.v4.app.Fragment.performCreateView(Fragment.java:2087)?
                  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1113)?
                  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1295)?
                  at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:801)?
                  at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1682)?
                  at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:541)?
                  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(Native Method)?
                  at java.lang.reflect.Method.invoke(Method.java:372)?
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)?
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)?
Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you use androidx.appcompat:appcompat:1.1.0, try androidx.appcompat:appcompat:1.0.2 instead. it seems that 1.1.0 doesn't fix the bug with WebView in Android 5.1.1.

Feb-2020 update: Reverting to 1.0.2 stopped working for many people (including my app), but using the current version of androidx.appcompat:appcompat:1.2.0-alpha02 did fix the crash. (I was seeing it on a Huawei P8 Lite running Android 5.0 during Google's automated "Pre-launch report" testing).

Jun-2020 update: There are newer releases available than the one mentioned in the Feb-2020 update, you can see the currently available versions here:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...