title: goBack() is making my app force close when hitting the back button
body: <p>I am trying to make the back button of an android device be a way of navigating backwards in a WebView. However, when I click the back button, it force closes instead.</p>
  
  <p>This is my .java file (edited out package name):</p>
  
  <pre><code>package ----;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.view.KeyEvent;
  import android.view.View;
  import android.webkit.WebSettings;
  import android.webkit.WebView;
  import android.webkit.WebViewClient;
  
  public class ---- extends Activity {
  WebView mainWebView;
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      WebView mainWebView = (WebView) findViewById(R.id.mainWebView);
  
      WebSettings webSettings = mainWebView.getSettings();
      webSettings.setJavaScriptEnabled(true);
  
      mainWebView.setWebViewClient(new MyCustomWebViewClient());
      mainWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
  
      mainWebView.loadUrl("https://app.tent.is/global");
  }
  
  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
      // Check if the key event was the Back button and if there's history
      if ((keyCode == KeyEvent.KEYCODE_BACK) &amp;&amp; mainWebView.canGoBack()) {
          mainWebView.goBack();
          return true;
      }
      // If it wasn't the Back key or there's no web page history, bubble up to the default
      // system behavior (probably exit the activity)
      return super.onKeyDown(keyCode, event);
  }
  
  private class MyCustomWebViewClient extends WebViewClient {
      @Override
      public boolean shouldOverrideUrlLoading(WebView view, String url) {
          view.loadUrl(url);
          return true;
      }
    }
  }
  </code></pre>