title: inputStream.read() null pointer exception
body: <p>I have sometimes error but can't understand why : </p>
  
  <p>Code :</p>
  
  <pre><code>public void newConnect()
          { try {
            urlka = new URL(myUrl);
  
          } catch (MalformedURLException e) {
  
              e.printStackTrace();
          }
            HttpURLConnection conn = null;
          try {
              conn = (HttpURLConnection) urlka.openConnection();
              conn.connect();
              Log.v("Responcse code","Response code " +conn.getResponseCode());
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
             try {
               try {
                  in = new BufferedInputStream(conn.getInputStream());
  
               } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
            result =  readStream(in); /// line 1198
  
             }
              finally {
               conn.disconnect();
             }
  </code></pre>
  
  <p>readStrem () </p>
  
  <pre><code>private String readStream(InputStream is)
          {
                      try 
                      {
                        ByteArrayOutputStream bo = new ByteArrayOutputStream();
                       int i = is.read(); /// **error was here** line 1247
  
  
                        while(i != -1) 
                        {
                          bo.write(i);
  
                          i = is.read();
                        }
  
                        return bo.toString();
                      } catch (IOException e) 
                      {
                        return ""+e;
                      }
          }
              }
  </code></pre>
  
  <p>Logcat:</p>
  
  <pre><code>java.lang.RuntimeException: An error occured while executing doInBackground()
      at android.os.AsyncTask$3.done(AsyncTask.java:200)
      at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
      at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
      at java.util.concurrent.FutureTask.run(FutureTask.java:137)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
      at java.lang.Thread.run(Thread.java:1096)
  Caused by: java.lang.NullPointerException
      at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl$LocalCloseInputStream.read(HttpURLConnectionImpl.java:167)
      at java.io.BufferedInputStream.fillbuf(BufferedInputStream.java:157)
      at java.io.BufferedInputStream.read(BufferedInputStream.java:243)
      at myApp.activity.com.myApp.readStream(myApp.java:1247)
      at myApp.activity.com.myApp.newConnect(myApp.java:1198)
      at myApp.activity.com.myApp$newRun.doInBackground(myApp.java:424)
      at myApp.activity.com.myApp$newRun.doInBackground(myApp.java:1)
      at android.os.AsyncTask$2.call(AsyncTask.java:185)
      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
  </code></pre>
  
  <p>This error is sometimes. But it's error :( Can any help me solve this problem ?
  I can't undestand why this error.</p>
  
  <p>Regards, Peter.</p>