これは私のAsyncTaskクラスです。
class AsyncLoad extends AsyncTask<Void, Void, ArrayList<ListData>> {
int i = 0;
protected ArrayList<ListData>[] onPostExecute(ArrayList<ListData>... result) {
return result;
}
protected ArrayList<ListData> doInBackground(Void... parameter) {
ArrayList<ListData> news = null;
int[] id = { 1, 2, 3, 4, 5 };
String[] title = { "title1", "title2", "title3", "title4", "title5" };
String[] category = { "category1", "category2", "category3",
"category4", "category5" };
int[] image = { R.drawable.pic01, R.drawable.pic02, R.drawable.pic03,
R.drawable.pic04, R.drawable.pic05, R.drawable.pic06 };
for (i = 0; i <= id.length - 1; i++) {
news.add(new ListData(id[i], title[i], category[i], image[i]));
}
return news;
}
}
このタスクを実行しようとすると、次のエラーが発生します:LOG
02-24 21:44:51.265: E/AndroidRuntime(7684): FATAL EXCEPTION: AsyncTask #1
02-24 21:44:51.265: E/AndroidRuntime(7684): java.lang.RuntimeException: An error occured while executing doInBackground()
02-24 21:44:51.265: E/AndroidRuntime(7684): at android.os.AsyncTask$3.done(AsyncTask.java:278)
02-24 21:44:51.265: E/AndroidRuntime(7684): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
02-24 21:44:51.265: E/AndroidRuntime(7684): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
02-24 21:44:51.265: E/AndroidRuntime(7684): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
02-24 21:44:51.265: E/AndroidRuntime(7684): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
02-24 21:44:51.265: E/AndroidRuntime(7684): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
02-24 21:44:51.265: E/AndroidRuntime(7684): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
02-24 21:44:51.265: E/AndroidRuntime(7684): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
02-24 21:44:51.265: E/AndroidRuntime(7684): at java.lang.Thread.run(Thread.java:856)
02-24 21:44:51.265: E/AndroidRuntime(7684): Caused by: java.lang.NullPointerException
そしてこれはListData.javaです:
package com.example.test2;
public class ListData {
int id;
String title;
String category;
int image;
ListData(int _id, String _title, String _category, int _image) {
id = _id;
title = _title;
category = _category;
image = _image;
}
}
そして、MainActivityではAsynTaskを実行しています(AsyncLoad load = new AsyncLoad(); load.execute();)
私が間違っている場所を見つけるのを手伝ってください!