7

This question is not duplicate, I know how to fix NPE in project, this NPE occurred in native method

as you can see I get :

Caused by: java.lang.NullPointerException at android.content.res.AssetManager.addAssetPathNative(Native Method)

I'v faced with following error After test my application in Android 8.0.0 for inflating 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

I've create new sample application with only one WebView in layout and problem exists on it, so it's not problem of my application.

I didn't find any workaround for this issue.

Thanks in advance

PS: this is my layout file:

<?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/");
    }
}

manifest file:

<?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: This application work fine in other android versions.

PS-3: did you want face with this issue? create one sample project and add one WebView in xml code, then run on android 8

PS-4: related questions but is not same: android-O : app crash with webview

Answer:

As I see, all application with webView ( even system part like Legal information ) crashed after opening webView pages, after updating webView issue has been solved.

2 Answers2

0
    WebView webView = (WebView) findViewById(R.id.webView);
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webView.setWebViewClient(new WebViewClient() {


        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
        //Do some like progress bar loading here.

        }

        @Override
        public void onPageFinished(WebView view, String url) {

        webView.loadUrl(sourceURL);

        }
    });

I just tested it out and it works fine. Please try this.

Jason
  • 102
  • 11
  • I've added my codes, I've got NPE in native method not in my application –  Sep 18 '17 at 04:53
0

Might be the same thing I am running into: https://developer.android.com/preview/features/security-behav

Note the part about how WebView's cannot be shared across processes starting in Android 8

astryk
  • 1,246
  • 13
  • 20