加载webview时出错类android.webkit.WebView时出错

时间:2014-09-07 09:27:32

标签: java android xml android-fragments webview

我之前从未遇到过这个问题,而且我的设置与之前的情况几乎相同。

错误本身就是:

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_width="match_parent"
    android:layout_height="match_parent"
    >

    <WebView
        android:id="@+id/facebookWebview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:paddingBottom="0dp"
        android:paddingLeft="0dp"
        android:paddingRight="0dp"
        android:paddingTop="0dp" />

</RelativeLayout>

我正在使用制表符片段,启动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 Manager,其中的所有内容都是最新的

1 个答案:

答案 0 :(得分:2)

感谢Tom R的答案。

如果有其他人遇到类似的问题,请检查您正在运行的模拟器。

看来我正在为Android Wear, more info can be found here on this if you are unaware运行模拟器。

通过将此更改为ARM CPU

中的标准Wear ARM来解决此问题