Java Android异步任务边界外异常

Java Android异步任务边界外异常,java,android,android-asynctask,Java,Android,Android Asynctask,我的股票报价申请有错误。我有一个应用程序,你可以输入你的a股代码(如股票市场代码),然后用两个按钮列出。一个按钮用于显示报价,另一个按钮用于查看来自web的更多信息。web功能很好,但当我点击quote按钮时,应用程序崩溃了 我认为这就是所讨论的方法 @Override protected String doInBackground(String... args) { try { URL url = new URL(args[0]);

我的股票报价申请有错误。我有一个应用程序,你可以输入你的a股代码(如股票市场代码),然后用两个按钮列出。一个按钮用于显示报价,另一个按钮用于查看来自web的更多信息。web功能很好,但当我点击quote按钮时,应用程序崩溃了

我认为这就是所讨论的方法

@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 &&  nl.getLength() > 0) {

                    for(int i=0; i < 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;
    }

很抱歉,我在隔离问题时遇到了困难。

发布相关代码,我们不会搜索整个项目。logcat会准确地告诉您问题所在。请发布它。请遵循@tyczj的建议。在此处发布相关代码,这样我们就不必查看您的问题对链接的编辑修订。
原因:java.lang.ArrayIndexOutOfBoundsException:length=0;index=0 10-02 02:59:52.738:E/AndroidRuntime(26553):在com.example.stockquote.StockInfoActivity$MyAsyncTask.doInBackground(StockInfoActivity.java:93)
哪一个是第93行?然后
args
为空。无法获取空数组的第一个元素(
args[0]
)!我怀疑当您调用
doInBackground
时,您没有传递URL数组。
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