1

尽管它似乎在我的设备和其他设备上运行良好,但在发布时,我似乎为大量用户收到了这个 NullPointerException,我用一个 try catch 包围它以防止崩溃,但我仍然被报告所困扰。

0java.lang.NullPointerException
1at broakenmedia.wiredmagazine.MainActivity$loadWebsite$1.onProgressChanged(MainActivity.java:331)
2at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:359)
3at android.os.Handler.dispatchMessage(Handler.java:99)
4at android.os.Looper.loop(Looper.java:132)
5at android.app.ActivityThread.main(ActivityThread.java:4126)
6at java.lang.reflect.Method.invokeNative(Native Method)
7at java.lang.reflect.Method.invoke(Method.java:491)
8at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
9at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
10at dalvik.system.NativeStart.main(Native Method)

代码:

  @SuppressWarnings("rawtypes")
        private class loadWebsite extends AsyncTask{
            private WebView webview;


       @Override
    protected Object doInBackground(Object... arg0) {
        webview = (WebView)findViewById(R.id.webView);

        webview.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(final WebView view, final int progress) {


                if(progress==100){
                    try {
                     pageLoading = (ProgressBar) findViewById(R.id.pageLoading);
                        pageLoading.setVisibility(View.GONE);
                 } catch (Exception e) {
                     // TODO Auto-generated catch block
                     BugSenseHandler.log("ProgressBarAt100", e);
                 }
                }
                else
                {
                    try {
                     pageLoading = (ProgressBar) findViewById(R.id.pageLoading);
                        pageLoading.setVisibility(View.VISIBLE);
                 } catch (Exception e) {
                     // TODO Auto-generated catch block
                     BugSenseHandler.log("ProgressBarAt0", e);
                 }
                }

                        //progressDialog.incrementProgressBy(progress);

                        //if(progress == 100 && progressDialog.isShowing())
                         //   progressDialog.dismiss();
                    }

                            }); 
        webview = (WebView)findViewById(R.id.webView);
        webview.setWebViewClient(new WebViewClient(){

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

            }
            public void onReceivedError(final WebView view, final int errorCode, 
                    final String description, final String failingUrl) {
                  if (errorCode == ERROR_TIMEOUT) {
                       view.stopLoading();  // may not be needed
        Toast.makeText(MainActivity.this,                         getString(R.string.an_error_occured_couldnt_load_page), 
                          Toast.LENGTH_SHORT).show(); 

        //view.loadData(timeoutMessageHtml, "text/html", "utf-8");
                   } 
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                try {
                    pageLoading = (ProgressBar) findViewById(R.id.pageLoading);
                    pageLoading.setVisibility(View.GONE);
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }
        });






        webview.getSettings().setSupportZoom(true);
        //webview.getSettings().setBuiltInZoomControls(true);
        webview.loadUrl("http://m.wired.com");
        return webview;
    }
    }
4

0 回答 0