Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is my program failing on getResponseCode()?
    text
    copied!<p>I am trying to do this tutorial: <a href="http://www.newthinktank.com/2013/05/android-development-tutorial-8/" rel="nofollow">http://www.newthinktank.com/2013/05/android-development-tutorial-8/</a></p> <p>For some reason, it appears to be failing on int responseCode = httpConnection.getResponseCode();</p> <p>All of the previous debug messages are working. I don't really understand how to use logcat errors, so if you need more logcat info, please tell me what to look for and I will reply with it.</p> <pre><code>private class MyAsyncTask extends AsyncTask&lt;String, String, String&gt; { @Override protected String doInBackground(String... args) { try{ Log.d(TAG, "Start doInBackground"); URL url = new URL(args[0]); Log.d(TAG, "URL"); URLConnection connection; connection = url.openConnection(); Log.d(TAG, "Open connection"); HttpURLConnection httpConnection = (HttpURLConnection)connection; Log.d(TAG, "httpConnection"); Log.d(TAG, ""+ httpConnection.getResponseCode()); int responseCode = httpConnection.getResponseCode(); Log.d(TAG, "Response code: " + responseCode); if(responseCode == HttpURLConnection.HTTP_OK) { Log.d(TAG, "Start if"); InputStream in = httpConnection.getInputStream(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document dom = db.parse(in); Element docEle = dom.getDocumentElement(); NodeList nl = docEle.getElementsByTagName("quote"); if(nl != null &amp;&amp; nl.getLength() &gt; 0) { Log.d(TAG, "Start second if"); for(int i = 0; i&lt;nl.getLength(); i++) { StockInfo theStock = getStockInformation(docEle); daysLow = theStock.getDaysLow(); daysHigh = theStock.getDaysHigh(); yearLow= theStock.getYearLow(); yearHigh = theStock.getYearHigh(); name = theStock.getName(); lastTradePriceOnly = theStock.getLastTradePriceOnly(); change = theStock.getChange(); daysRange = theStock.getDaysRange(); Log.d(TAG, "End doInBackground"); } } } } catch(MalformedURLException e) { Log.d(TAG, "MalformedURLException", e); } catch(IOException e) { Log.d(TAG, "IOException", e); } catch(ParserConfigurationException e) { Log.d(TAG, "Parser Configuration Exception", e); } catch (SAXException e) { Log.d(TAG, "SAX Exception", e); } finally{ } return null; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload