title: Problems with WebViewClient and onKeyDown
body: <p>I'm currently trying to make a WebView based app.</p>
  
  <p>This is the code I currently have:</p>
  
  <pre><code>    WebView webview = new WebView(this);
      setContentView(webview);
  
      WebView webView = (WebView) findViewById(R.id.myWebView);
      webview.getSettings().setJavaScriptEnabled(true);
      webview.getSettings().setLoadsImagesAutomatically(true);
  
      webView.setWebViewClient(new NewWebViewClient());
      webview.loadUrl("http://google.com");
  </code></pre>
  
  <p>And the "NewWebViewClient" class is under this also in the MainActivity.java</p>
  
  <pre><code>public class NewWebViewClient extends WebViewClient {
  
      @Override
      public boolean shouldOverrideUrlLoading(WebView view, String url) {
  
          view.loadUrl(url);
          return true;
      }
  }
  </code></pre>
  
  <p>There is no error shown by Android Studio.
  But if I want to start the app on my smartphone it just crashes.</p>
  
  <p>The same Problem I have with this:</p>
  
  <pre><code>public void onKeyDown() {
      WebView webView = (WebView) findViewById(R.id.myWebView);
  
      if (webView.copyBackForwardList().getCurrentIndex() &gt; 0) {
          webView.goBack();
      }
  
      else {
          super.onBackPressed();
      }
  
  }
  </code></pre>
  
  <p>Does anyone know how I get this both things get working?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>It still crashes:</p>
  
  <pre><code>Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.webkit.WebView.setWebViewClient(android.webkit.WebViewClient)' on a null object reference
  </code></pre>