我有活动 A 和 B。他们都有 AsyncTasks 连接到网络并获取一些 JSON。我得到一个我无法完全复制的错误,但我不确定我做错了什么。当我按下从活动 B 到 A 到主屏幕的返回按钮时出现错误。
堆栈跟踪:
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:299)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
at java.util.concurrent.FutureTask.run(FutureTask.java:239)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.NullPointerException
at com.mycompany.myapp.ActivityGD$GetMethod.doInBackground(ActivityGD.java:131)
at com.mycompany.myapp.ActivityGD$GetMethod.doInBackground(ActivityGD.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
... 4 more
我不知道我怎么能得到一个空指针,看起来像一个 AsyncTask。注意:ActivityGD = Activity B。所以本质上,我不明白当我简单地按下 Activity A 时,我是如何在 Activity B 上获得空指针的。
第 130 至 137 行
protected void onPostExecute(String response) {
String[] myText = final.split(",");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
ActivityGD.this, R.layout.simple_list_item_1,
myText);
setListAdapter(adapter);
}