0

我正在构建一个 android 应用程序,该应用程序涉及从文件中读取文本并对它们进行一些操作。我正在使用线程(我将输入流对象(in)传递给线程(AsyncTask))。我已经成功地从文件中提取了模式,但是在我将 ArrayList 转换为 String 数组的下一行中发生了错误(在调试模式下)。

String[] str=a.toArray(new String[a.size()]);

我的代码是(在doInBackground里面):

BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null) {
    Matcher m = MY_PATTERN.matcher(strLine);
    a = new ArrayList<String>();
    while (m.find()) {
        a.add(m.group(1));
        // s now contains "BAR"
    }
    String[] str=a.toArray(new String[a.size()]);//ERROR STEP
              double ltdo=(Math.round(Double.parseDouble(lt)*100.0)/100.0);
              double lodo=(Math.round(Double.parseDouble(lo)*100.0)/100.0);
}

我的目录错误是:

08-15 16:38:12.980: I/global(384): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
08-15 16:38:52.972: W/dalvikvm(384): threadid=8: thread exiting with uncaught exception (group=0x4001d800)
08-15 16:38:53.360: E/AndroidRuntime(384): FATAL EXCEPTION: AsyncTask #1
08-15 16:38:53.360: E/AndroidRuntime(384): java.lang.RuntimeException: An error occured while executing doInBackground()
08-15 16:38:53.360: E/AndroidRuntime(384):  at android.os.AsyncTask$3.done(AsyncTask.java:200)
08-15 16:38:53.360: E/AndroidRuntime(384):  at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
08-15 16:38:53.360: E/AndroidRuntime(384):  at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
08-15 16:38:53.360: E/AndroidRuntime(384):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
08-15 16:38:53.360: E/AndroidRuntime(384):  at java.util.concurrent.FutureTask.run(FutureTask.java:137)
08-15 16:38:53.360: E/AndroidRuntime(384):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
08-15 16:38:53.360: E/AndroidRuntime(384):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
08-15 16:38:53.360: E/AndroidRuntime(384):  at java.lang.Thread.run(Thread.java:1096)
08-15 16:38:53.360: E/AndroidRuntime(384): Caused by: java.lang.NullPointerException
08-15 16:38:53.360: E/AndroidRuntime(384):  at org.apache.harmony.luni.util.FloatingPointParser.parseDouble(FloatingPointParser.java:263)
08-15 16:38:53.360: E/AndroidRuntime(384):  at java.lang.Double.parseDouble(Double.java:287)
08-15 16:38:53.360: E/AndroidRuntime(384):  at my.GPS.FindLocation.doInBackground(FindLocation.java:67)
08-15 16:38:53.360: E/AndroidRuntime(384):  at my.GPS.FindLocation.doInBackground(FindLocation.java:1)
08-15 16:38:53.360: E/AndroidRuntime(384):  at android.os.AsyncTask$2.call(AsyncTask.java:185)
08-15 16:38:53.360: E/AndroidRuntime(384):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
08-15 16:38:53.360: E/AndroidRuntime(384):  ... 4 more
4

0 回答 0