title: DocumentBuilder parse exception
body: <p>I am new to Java &amp; Android.</p>
  
  <p>I am trying to parse InputStream at the context of AsyncTask and getting an exception.
  What am I doing wrong?</p>
  
  <pre><code> public Integer doInBackground(String... url)
  {
      HttpURLConnection con = null;
      int status = ResultStatus.STATUS_OK;
      InputStream in = null;
  
      ConnectivityManager cm = (ConnectivityManager) mainActivityContext.getSystemService(Context.CONNECTIVITY_SERVICE);
  
      if (cm.getActiveNetworkInfo() == null)
          return ResultStatus.CONNECTION_FAILED;
  
      try
      {
          URL bank_url = new URL(url[0]);
          con = (HttpURLConnection) bank_url.openConnection();
          con.getResponseCode();
          con.setRequestMethod("GET");
          con.connect();
          in = con.getInputStream();
      }
      catch (IOException e)
      {
          status = ResultStatus.URL_NOT_FOUND;
      }
      finally
      {
          con.disconnect();
      }
  
      try
      {
          DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
          DocumentBuilder builder = factory.newDocumentBuilder();
          Document doc = builder.parse(in);    &lt;&lt;&lt;&lt;----Here I get an exception
      }
      catch (Exception e)
      {
          e.printStackTrace();
      }
  
      return status;
  }
  </code></pre>
  
  <p>I get an exception which appears at:   Document doc = builder.parse(in);</p>
  
  <p>The exception output:</p>
  
  <pre><code>-13 14:11:26.651 13568-14118/com.course.rita.currencyexchange W/System.err: java.io.IOException: closed
  02-13 14:11:26.661 13568-13575/com.course.rita.currencyexchange W/art: Suspending all threads took: 7.999ms
  02-13 14:11:26.661 13568-14118/com.course.rita.currencyexchange W/System.err:     at com.android.okio.RealBufferedSource$1.read(RealBufferedSource.java:158)
  02-13 14:11:26.661 13568-14118/com.course.rita.currencyexchange W/System.err:     at org.kxml2.io.KXmlParser.setInput(KXmlParser.java:1642)
  02-13 14:11:26.661 13568-14118/com.course.rita.currencyexchange W/System.err:     at org.apache.harmony.xml.parsers.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:111)
  02-13 14:11:26.661 13568-14118/com.course.rita.currencyexchange W/System.err:     at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:107)
  02-13 14:11:26.661 13568-14118/com.course.rita.currencyexchange W/System.err:     at com.course.rita.currencyexchange.ReadCurrencyRateTask.doInBackground(ReadCurrencyRateTask.java:86)
  02-13 14:11:26.661 13568-14118/com.course.rita.currencyexchange W/System.err:     at com.course.rita.currencyexchange.ReadCurrencyRateTask.doInBackground(ReadCurrencyRateTask.java:34)
  02-13 14:11:26.661 13568-14118/com.course.rita.currencyexchange W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:288)
  02-13 14:11:26.661 13568-14118/com.course.rita.currencyexchange W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
  02-13 14:11:26.661 13568-14118/com.course.rita.currencyexchange W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
  02-13 14:11:26.661 13568-14118/com.course.rita.currencyexchange W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
  </code></pre>
  
  <p>Thanks</p>