私のデバイスや他のデバイスでは正常に動作しているように見えますが、公開すると、膨大な数のユーザーに対してこの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;
}
}