刷新刷新时,Android webview强制关闭

时间:2016-03-22 18:24:52

标签: android webview swipe

Webview正确启动并运行。但是如果我使用滑动刷新WebView,应用程序将关闭。请帮我。谢谢。

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    mySwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout);

    mySwipeRefreshLayout.setColorSchemeResources(R.color.quogito_color);

    WebView myWebView = (WebView) findViewById(R.id.webview);

    WebSettings webSettings = myWebView.getSettings();

    webSettings.setJavaScriptEnabled(true);

    webSettings.setLoadsImagesAutomatically(true);

    MyWebViewClient myWebViewClient = new MyWebViewClient();

    myWebView.setWebViewClient(myWebViewClient);

    myWebView.loadUrl(website_url);

    mySwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            mySwipeRefreshLayout.setRefreshing(true);
            refreshPage();
        }
    });
    this.onStart();
}

崩溃日志

03-22 20:19:24.860 24789-24863/com.quogito.quogito I/OpenGLRenderer: Initialized EGL, version 1.4
03-22 20:19:25.260 24789-24789/com.quogito.quogito I/chromium: [INFO:CONSOLE(6)] "Uncaught Error: Bootstrap's JavaScript requires jQuery", source: https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js (6)
03-22 20:19:30.870 24789-24789/com.quogito.quogito E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.quogito.quogito, PID: 24789
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.webkit.WebView.reload()' on a null object reference
at com.quogito.quogito.MainActivity.refreshPage(MainActivity.java:147)
at com.quogito.quogito.MainActivity$1.onRefresh(MainActivity.java:131)
at android.support.v4.widget.SwipeRefreshLayout$1.onAnimationEnd(SwipeRefreshLayout.java:185)
at android.support.v4.widget.CircleImageView.onAnimationEnd(CircleImageView.java:107)

1 个答案:

答案 0 :(得分:1)

你没有在oncreate方法上初始化你的“myWebView”,你应该这样做......

 myWebView = (WebView) findViewById(R.id.XXXXX);