Zoltan Szilagyi
Zoltan Szilagyi

Reputation: 292

Fatal signal 6 (sigabrt) (code=-6) webview

So I have got a webview, and a menu. It's working fine, when I open. I set that if the webview progress not 0 or not 100 (so when loading page) the webview reload menu item invisible (so you can't see), and the stop menu item is visible. And if the webview loaded the page (so the progress 100) or can't load the page (the progress 0) the reload menu item going to visible, and the stop menu item will go to invisible. I sayed, that it's working fine... UNTIL I quit the app. (I don't clear from the system history).

I reopened the app. crash! Why? If I delete from the system history the app, it doesn't crashes. I destroyed the activity (in code) but it isn't working.

 // ...
 @Override
 public void onProgressChanged(WebView view, int progress) {
     progressBarLoad.setProgress(progress);
     int prInt = progressBarLoad.getProgress();
     if (prInt > 0 && prInt < 100) {
         menuMain.findItem(R.id.MenuExit).setVisible(true);
         menuMain.findItem(R.id.MenuReload).setVisible(false);
         }
     if (prInt == 100 || prInt == 0) {
         menuMain.findItem(R.id.MenuExit).setVisible(false);
         menuMain.findItem(R.id.MenuReload).setVisible(true);
         }
     }
 //...

OnKeyDown:

 @Override
    public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && !webViewMain.canGoBack()) {
            if (booleanOnKeyDown) {
                new AlertDialog.Builder(this)
                        .setTitle(getString(R.string.SureExitTitle))
                        .setPositiveButton(getString(R.string.Yes), new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                finish();
                                onDestroy();
                            }
                        })
                        .setNegativeButton(getString(R.string.No), new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                            }
                        }).show();
            }
        }
        return super.onKeyDown(keyCode, event);
    }

The log:

10-26 12:41:15.867  14008-14008/com.zokni1996.android_forum W/System.err﹕ java.lang.NullPointerException
10-26 12:41:15.867  14008-14008/com.zokni1996.android_forum W/System.err﹕ at com.zokni1996.android_forum.Main.Main$6.onProgressChanged(Main.java:451)
10-26 12:41:15.867  14008-14008/com.zokni1996.android_forum W/System.err﹕ at com.android.webview.chromium.WebViewContentsClientAdapter.onProgressChanged(WebViewContentsClientAdapter.java:271)

Upvotes: 3

Views: 5552

Answers (1)

Zoltan Szilagyi
Zoltan Szilagyi

Reputation: 292

I solved the problem (yes, it's a very very bad solution). It was a nullpoint exception. I used try-catch.

// ...
@Override
public void onProgressChanged(WebView view, int progress) {
    progressBarLoad.setProgress(progress);
    if (progressBarLoad.getProgress() > 0 && progressBarLoad.getProgress() < 100) {
        try {
            menuMain.findItem(R.id.MenuExit).setVisible(true);
            menuMain.findItem(R.id.MenuReload).setVisible(false);
        } catch (Exception e) {
            Log.i("Menu failed reload or stop ", "" + e);
        }
    } else {
        try {
            menuMain.findItem(R.id.MenuExit).setVisible(false);
            menuMain.findItem(R.id.MenuReload).setVisible(true);
        } catch (Exception e) {
            Log.i("Menu failed reload or stop", "" + e);
        }
    }
}
//...

Upvotes: 1

Related Questions