Webview android应用程序崩溃,出现错误" java.lang.NullPointerException"

时间:2017-01-15 02:59:57

标签: java android webview

这是一个使用WebView显示网站的简单应用程序。应用程序运行一段时间但是当我继续使用它时,它崩溃并给出以下错误。

E/AndroidRuntime: FATAL EXCEPTION: main
              Process: com.example.sauhardachhetri.projeck, PID: 3733
              java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
                  at com.android.webview.chromium.WebViewContentsClientAdapter.getDefaultVideoPoster(WebViewContentsClientAdapter.java:1181)
                  at org.chromium.android_webview.DefaultVideoPosterRequestHandler$1.run(DefaultVideoPosterRequestHandler.java:39)
                  at android.os.Handler.handleCallback(Handler.java:751)
                  at android.os.Handler.dispatchMessage(Handler.java:95)
                  at android.os.Looper.loop(Looper.java:154)
                  at android.app.ActivityThread.main(ActivityThread.java:6119)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

片段java文件看起来像

package com.example.sauhardachhetri.projeck;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;



public class mobilePrice extends Fragment {


public mobilePrice() {
    // Required empty public constructor
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View rootview=inflater.inflate(R.layout.fragment_mobile_price,container,false);
    WebView Hell=((WebView)rootview.findViewById(R.id.mobilewebsurface));
    Hell.getSettings().setJavaScriptEnabled(true);
    Hell.setWebViewClient(new WebViewClient());
    Hell.loadUrl("http://www.gadgetsinnepal.com/category/mobile-price/");

    return rootview;
}

}

0 个答案:

没有答案