加载 webview 时膨胀类 android.webkit.WebView 时出错
Posted
技术标签:
【中文标题】加载 webview 时膨胀类 android.webkit.WebView 时出错【英文标题】:Error inflating class android.webkit.WebView when loading webview 【发布时间】:2014-10-31 18:16:55 【问题描述】:我以前从未遇到过这个问题,我的设置与以前的情况几乎相同。
其自身的错误是:
android.view.InflateException: Binary XML file line #7:
Error inflating class android.webkit.WebView
我在 XML 文件中启动 WebView
,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_
android:layout_
>
<WebView
android:id="@+id/facebookWebview"
android:layout_
android:layout_
android:paddingBottom="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp" />
</RelativeLayout>
我用的是tab片段,启动xml文件的片段是这样的:
public class FragmentTab1 extends Fragment
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
View view = inflater.inflate(R.layout.tabfacebook, container, false);
// allocate and instanciate webview
WebView webView = (WebView) view.findViewById(R.id.facebookWebview);
webView.getSettings().setjavascriptEnabled(true);
// load fb url into it
webView.loadUrl("https://www.facebook.com/urlinhere");
webView.setWebViewClient(new WebViewClient()
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
Log.d("TAG", " ==> " + url);
view.loadUrl(url);
return true;
);
return view;
再一次,这是我一直这样做的。我已经注释掉了这段代码的大部分,看看问题是否在这里,但是它在 XML 文件中而不是 .java 文件中。
有什么建议吗?
编辑:整个堆栈跟踪
09-07 09:19:06.870 1150-1150/ourpackage.com.ourpackage E/WebViewFactory﹕ Chromium WebView does not exist
09-07 09:19:06.910 1150-1150/ourpackage.com.ourpackage E/WebViewFactory﹕ Chromium WebView does not exist
09-07 09:19:06.910 1150-1150/ourpackage.com.ourpackage D/AndroidRuntime﹕ Shutting down VM
09-07 09:19:06.910 1150-1150/ourpackage.com.ourpackage W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb1a46d70)
android.view.InflateException: Binary XML file line #7: Error inflating class android.webkit.WebView
at android.view.LayoutInflater.createView(LayoutInflater.java:620)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:57)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at ourpackage.com.ourpackage.FragmentTab1.onCreateView(FragmentTab1.java:22)
at android.app.Fragment.performCreateView(Fragment.java:1701)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:890)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1063)
at android.app.BackStackRecord.run(BackStackRecord.java:684)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1448)
at android.app.FragmentManagerImpl$1.run(FragmentManager.java:443)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5026)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:57)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at ourpackage.com.ourpackage.FragmentTab1.onCreateView(FragmentTab1.java:22)
at android.app.Fragment.performCreateView(Fragment.java:1701)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:890)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1063)
at android.app.BackStackRecord.run(BackStackRecord.java:684)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1448)
at android.app.FragmentManagerImpl$1.run(FragmentManager.java:443)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5026)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.UnsupportedOperationException
at com.android.webview.nullwebview.NullWebViewFactoryProvider.createWebView(NullWebViewFactoryProvider.java:41)
at android.webkit.WebView.ensureProviderCreated(WebView.java:2058)
at android.webkit.WebView.setOverScrollMode(WebView.java:2116)
at android.view.View.<init>(View.java:3461)
at android.view.View.<init>(View.java:3517)
at android.view.ViewGroup.<init>(ViewGroup.java:470)
at android.widget.AbsoluteLayout.<init>(AbsoluteLayout.java:52)
at android.webkit.WebView.<init>(WebView.java:498)
at android.webkit.WebView.<init>(WebView.java:475)
at android.webkit.WebView.<init>(WebView.java:455)
at android.webkit.WebView.<init>(WebView.java:444)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:57)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at ourpackage.com.ourpackage.FragmentTab1.onCreateView(FragmentTab1.java:22)
at android.app.Fragment.performCreateView(Fragment.java:1701)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:890)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1063)
at android.app.BackStackRecord.run(BackStackRecord.java:684)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1448)
at android.app.FragmentManagerImpl$1.run(FragmentManager.java:443)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5026)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(Native Method)
我检查了我的 SDK 管理器,里面的一切都是最新的
【问题讨论】:
第 22 行在哪里? 只是快速猜测一下,您的清单中是否包含 INTERNET 权限? @JoshBoothe 请同时发布您的清单文件,这可能与 Activity 上设置的主题有关。 这是问题所在,当然Android Wear模拟器不支持Chromium,所以报错.. 没问题,请随时回答您自己的问题,以防其他人将来遇到类似问题。 【参考方案1】:感谢 Tom R 的回答。
如果其他人遇到类似问题,请检查您正在运行的模拟器。
看来我正在为Android Wear, more info can be found here on this if you are unaware 运行模拟器。
通过将其从 Wear ARM
更改为仅标准的 ARM CPU
已修复
【讨论】:
谢谢,这对我有点帮助。不幸的是,我在不同的环境中面临同样的错误和堆栈跟踪:我有一个实时应用程序,并在 HockeyApp 中随机获取这些崩溃报告。它们分布在各种设备上,但主要是 Nexus 设备。我的应用没有磨损模块或类似的东西。有什么想法吗? @MatthiasWenz 你有解决办法吗? @AymanMahgoub 不幸的是没有。错误一直存在,我们无法追踪。 似乎***.com/questions/31732169/… 有解释。以上是关于加载 webview 时膨胀类 android.webkit.WebView 时出错的主要内容,如果未能解决你的问题,请参考以下文章
膨胀类 ImageView 时出错 - android.view.InflateException:二进制 XML 文件第 10 行:膨胀类 ImageView 时出错