Android O中的WebView崩溃

时间:2017-09-18 04:47:42

标签: android webview

这个问题不重复,我知道如何在项目中修复NPE,这个NPE发生在原生方法

你可以看到我得到:

引起:java.lang.NullPointerException     在android.content.res.AssetManager.addAssetPathNative(原生方法)

我遇到了以下错误在Android 8.0.0中测试我的应用程序后,为WebView充气。

    FATAL EXCEPTION: main
Process: com.example.shpoorvatan.myapplication, PID: 17952
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.shpoorvatan.myapplication/com.example.shpoorvatan.myapplication.MainActivity}: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class android.webkit.WebView
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
    at android.app.ActivityThread.-wrap11(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6541)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
 Caused by: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class android.webkit.WebView
 Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class android.webkit.WebView
 Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Constructor.newInstance0(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
    at android.view.LayoutInflater.createView(LayoutInflater.java:647)
    at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:720)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
    at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
    at com.example.shpoorvatan.myapplication.MainActivity.onCreate(MainActivity.java:12)
    at android.app.Activity.performCreate(Activity.java:6975)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
    at android.app.ActivityThread.-wrap11(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6541)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
 Caused by: java.lang.NullPointerException
    at android.content.res.AssetManager.addAssetPathNative(Native Method)
    at android.content.res.AssetManager.addAssetPathInternal(AssetManager.java:689)
    at android.content.res.AssetManager.addAssetPathAsSharedLibrary(AssetManager.java:684)
    at android.webkit.WebViewFactory.getProviderClass(WebViewFactory.java:407)
    at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:211)
    at android.webkit.WebView.getFactory(WebView.java:2467)
    at android.webkit.WebView.ensureProviderCreated(WebView.java:2462)
    at android.webkit.WebView.setOverScrollMode(WebView.java:2527)
    at android.view.View.<init>(View.java:4536)
    at android.view.View.<init>(View.java:4668)
    at android.view.ViewGroup.<init>(ViewGroup.java:597)
    at android.widget.AbsoluteLayout.<init>(AbsoluteLayout.java:55)
    at android.webkit.WebView.<init>(WebView.java:636)
    at android.webkit.WebView.<init>(WebView.java:581)
    at android.webkit.WebView.<init>(WebView.java:564)
    at android.webkit.WebView.<init>(WebView.java:551)
        ... 27 more

我创建了新的示例应用程序,其中只有一个WebView布局并且存在问题,所以它不是我的应用程序的问题。

我没有找到解决此问题的方法。

提前致谢

PS:这是我的布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.shpoorvatan.myapplication.MainActivity">

    <WebView
        android:id="@+id/webView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>

java class:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        WebView webView = (WebView) findViewById(R.id.webView);
        webView.loadUrl("https://www.google.com/");
    }
}

清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.shpoorvatan.myapplication">

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

PS-2:此应用程序在其他Android版本中运行良好。

PS-3:你想要面对这个问题吗?创建一个示例项目并在WebView代码中添加一个xml,然后在android 8上运行

PS-4:相关问题但不相同:android-O : app crash with webview

答案:

正如我所看到的,在更新webView问题后,所有webView的应用程序(甚至系统部分如法律信息)都会在打开webView页后崩溃。

2 个答案:

答案 0 :(得分:0)

&&

我刚刚测试了它,它运行正常。请试试这个。

答案 1 :(得分:0)

可能与我遇到的事情一样:fdopen()

请注意有关如何从Android 8开始无法跨进程共享WebView的部分