title: Declaring InputStream
body: <p>I am learning android and new to Java but not new to programming (Using Eclipse). I am trying to execute an example code like this in a method:</p>
  
  <pre><code>private void dummy() {
      try {
          URL url = new URL(quakeFeed);
          URLConnection connection;
          connection = url.openConnection();
          HttpURLConnection httpconnection = (HttpURLConnection)connection;
          int responseCode = httpconnection.getResponseCode();
          if(responseCode == HttpURLConnection.HTTP_OK)
              InputStream inp = new BufferedInputStream(httpconnection.getInputStream());
      }
  ...
  }
  </code></pre>
  
  <p>Assume all other syntax and variables defined. I get the following error:</p>
  
  <blockquote>
    <p>InputStream` cannot be resolved to a variable. </p>
  </blockquote>
  
  <p>This is strange even after importing <code>java.io.InputStream;</code></p>
  
  <p>The error goes off if I declare the <code>InputStream</code> outside the method, i.e.</p>
  
  <pre><code>InputStream inp;
  private void dummy() {
      try {
          URL url = new URL(quakeFeed);
          URLConnection connection;
          connection = url.openConnection();
          HttpURLConnection httpconnection = (HttpURLConnection)connection;
          int responseCode = httpconnection.getResponseCode();
          if(responseCode == HttpURLConnection.HTTP_OK)
          // Changed
              inp = new BufferedInputStream(httpconnection.getInputStream());
      }
      ...
  }
  </code></pre>
  
  <p>I am curious why a local declaration of <code>InputStream</code> could not be resolved but a global declaration is resolved.</p>