title: Variable view might not have initialized and Variable view accessed from inner view
body: <p>I've gone through lots of post and forums but couldn't find solution. I'm developing an application with local html files inside for which I've this one main activity</p>
  
  <pre><code>package com.faraksoch.sagar.eroutine;
  
  
  
  public class MainActivity extends AppCompatActivity {
  boolean doubleBackToExitPressed = false;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      WebView webView = (WebView) findViewById(webView);
  
  
      webView.getSettings().setJavaScriptEnabled(true);
      webView.getSettings().setAppCacheEnabled(true);
      webView.getSettings().setSupportZoom(true);
      webView.getSettings().setAllowFileAccess(true);
  
  
      webView.setWebViewClient(new WebViewClient() {
  
  
          public void onPageFinished(WebView view, String url) {
              findViewById(R.id.image1).setVisibility((View.GONE));
              findViewById(webView).setVisibility(View.VISIBLE);
  
  
          }
      });
  
  
      webView.loadUrl("file:///android_asset/index.html");
  
      webView.setDownloadListener(new DownloadListener() {
          public void onDownloadStart(String url, String userAgent,
                                      String contentDisposition, String mimetype,
                                      long contentLength) {
              Intent i = new Intent(Intent.ACTION_VIEW);
              i.setData(Uri.parse(url));
              startActivity(i);
          }
      });
  
      Intent intent = new Intent(MainActivity.this, UpdateService.class);
      startService(intent);
  }
  
  boolean doubleBackToExitPressedOnce = false;
  
  @Override
  public void onBackPressed() {
      if (doubleBackToExitPressedOnce) {
          super.onBackPressed();
          return;
      }
  
      this.doubleBackToExitPressedOnce = true;
      Toast.makeText(this, "Please click BACK again to exit",
              Toast.LENGTH_SHORT).show();
  
      new Handler().postDelayed(new Runnable() {
  
          @Override
          public void run() {
              doubleBackToExitPressedOnce = false;
          }
      }, 2000);
  
  
  }
  WebView webView;
  public void goBack(){
      if (webView.canGoBack()) {
          webView.goBack();
      } else {
          finish();
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Here in line</p>
  
  <pre><code>WebView webView = (WebView) findViewById(webView);
  </code></pre>
  
  <p>I'm getting error of webView might not have been initialized and on line</p>
  
  <pre><code>findViewById(webView).setVisibility(View.VISIBLE);
  </code></pre>
  
  <p>Variable webView is accessed from innter class which need to be declared final and thus when I change code to this</p>
  
  <pre><code> final WebView webView = (WebView) findViewById(webView);
  </code></pre>
  
  <p>still no luck.</p>
  
  <p>and my Main_activity file is</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.constraint.ConstraintLayout 
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context="com.faraksoch.sagar.eroutine.MainActivity"&gt;
  
  &lt;WebView
      android:id="@+id/webView"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:visibility="gone"
       /&gt;
  
  
  &lt;ImageView
      android:id="@+id/image1"
      android:layout_width="368dp"
      android:layout_height="576dp"
      android:background="@drawable/ssplash" /&gt;
  
  &lt;/android.support.constraint.ConstraintLayout&gt;
  </code></pre>
  
  <p>Can anyone help me with this, what must I do to make it work.</p>