Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid AsyncTask OutOfBoundsException
    primarykey
    data
    text
    <p>I have an error on my stock quoting application. I have an app where you input your a stock (as in stock market) code and will list it with two buttons. One button to display a quote and the other to view more info from the web. The web function is fine but the app crashes when I hit the quote button.</p> <p>I think that this is the method in question.</p> <pre><code>@Override protected String doInBackground(String... args) { try { URL url = new URL(args[0]); URLConnection connection; connection = url.openConnection(); HttpURLConnection httpConnection = (HttpURLConnection) connection; int responseCode = httpConnection.getResponseCode(); if(responseCode == HttpURLConnection.HTTP_OK) { 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) { for(int i=0; i &lt; nl.getLength(); i++){ StockInfo theStock = getStockInformation(docEle); name = theStock.getName(); yearLow = theStock.getYearLow(); yearHigh = theStock.getYearHigh(); daysLow = theStock.getDaysLow(); daysHigh = theStock.getDaysHigh(); lastTradePriceOnly = theStock.getLastTradePriceonly(); change = theStock.getChange(); daysRange = theStock.getDaysRange(); } } } } 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> <p>LogCat is showing that I have an OutOfBoundsException in doInBackground() of my StockInfoActivity class but I can't find it. Will appreciate any help in locating the problem.</p> <pre><code>10-02 02:59:52.738: E/AndroidRuntime(26553): FATAL EXCEPTION: AsyncTask #4 10-02 02:59:52.738: E/AndroidRuntime(26553): java.lang.RuntimeException: An error occured while executing doInBackground() 10-02 02:59:52.738: E/AndroidRuntime(26553): at android.os.AsyncTask$3.done(AsyncTask.java:299) 10-02 02:59:52.738: E/AndroidRuntime(26553): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352) 10-02 02:59:52.738: E/AndroidRuntime(26553): at java.util.concurrent.FutureTask.setException(FutureTask.java:219) 10-02 02:59:52.738: E/AndroidRuntime(26553): at java.util.concurrent.FutureTask.run(FutureTask.java:239) 10-02 02:59:52.738: E/AndroidRuntime(26553): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 10-02 02:59:52.738: E/AndroidRuntime(26553): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 10-02 02:59:52.738: E/AndroidRuntime(26553): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 10-02 02:59:52.738: E/AndroidRuntime(26553): at java.lang.Thread.run(Thread.java:841) 10-02 02:59:52.738: E/AndroidRuntime(26553): Caused by: java.lang.ArrayIndexOutOfBoundsException: length=0; index=0 10-02 02:59:52.738: E/AndroidRuntime(26553): at com.example.stockquote.StockInfoActivity$MyAsyncTask.doInBackground(StockInfoActivity.java:93) 10-02 02:59:52.738: E/AndroidRuntime(26553): at com.example.stockquote.StockInfoActivity$MyAsyncTask.doInBackground(StockInfoActivity.java:1) 10-02 02:59:52.738: E/AndroidRuntime(26553): at android.os.AsyncTask$2.call(AsyncTask.java:287) 10-02 02:59:52.738: E/AndroidRuntime(26553): at java.util.concurrent.FutureTask.run(FutureTask.java:234) 10-02 02:59:52.738: E/AndroidRuntime(26553): ... 4 more </code></pre> <p>Sorry I'm having a tough time isolating the problem.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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