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

So I have a webview and a menu. It works great when I open it. I have set that if the progress of the webview is not 0 or not 100 (so when the page loads) the webview reload menu item is invisible (so you cannot see) and the stop menu item is displayed. And if the webview has loaded the page (so progress is 100) or cannot load the page (progress 0), the reload menu item will become visible and the stop menu item will become invisible. I said it works fine ... BEFORE SHOULD NOT exit the application. (I don't understand from system history).

I opened the app again. bump into! What for? If I delete the application from the system history, it will not work. I destroyed the activity (in code) but it doesn't work.

 // ...
 @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);
    }

      

Magazine:

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)

      

+3


source to share


1 answer


I solved the problem (yes it is a very bad solution). This 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);
        }
    }
}
//...

      

+1


source







All Articles