title: Parse Exception: At line 1, column 0: no element found
body: <p>I have a weird issue. I receive the following error that causes a force-close:</p>
  
  <blockquote>
    <p>org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 0: no element found    at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:508)
    at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:467)
    at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:329)
    at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:286)</p>
  </blockquote>
  
  <p>After clicking the Force Close button, the Activity is recreated and the parsing completes without a hitch. I'm using the following code snippet inside doInBackground of an AsyncTask:</p>
  
  <pre><code>URL serverAddress = new URL(url[0]);
  
  HttpURLConnection connection = (HttpURLConnection) serverAddress.openConnection();
  connection.setRequestMethod("GET");
  connection.setDoOutput(true);
  connection.setReadTimeout(10000);
  connection.connect();
  
  InputStream stream = connection.getInputStream();
  
  SAXParserFactory spf = SAXParserFactory.newInstance();
  SAXParser sp = spf.newSAXParser();
  
  XMLReader xr = sp.getXMLReader();
  
  xr.parse(new InputSource(stream));  // The line that throws the exception
  </code></pre>
  
  <p>Why would the Activity force-close and then run without any problems immediately after? Would a BufferedInputStream be any different? I'm baffled. :(</p>
  
  <p>Thanks for your time everyone.</p>
  
  <p>Update: It turns out HttpURLConnection.getResponseCode() returns -1 every so often, so the InputStream probably isn't being correctly set.</p>