我有以下代码:
public class TestSynch extends Activity {
public static ArrayList<HashMap<String,String>> list;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Context ctx = this.getApplicationContext();
new ProcessFileTask().execute(ctx);
Intent i = new Intent(TestSynch.this, ListSchools.class);
i.setAction(Intent.ACTION_VIEW);
i.putExtra("arraylist", list);
startActivity(i);
}
private class ProcessFileTask extends AsyncTask<Context, Void, ArrayList<HashMap<String,String>>> {
@Override
protected ArrayList<HashMap<String,String>> doInBackground(Context... ctx) {
ArrayList<HashMap<String,String>> threadList = FileOperations.getListAsMaps(ctx[0]);
return threadList;
}
@Override
protected void onPostExecute(ArrayList<HashMap<String,String>> result) {
list = result;
return;
}
}
我可以调试到返回threadList;doInBackground 中的行,并且 ArrayList 变量 threadList 是完全正确的。
但是,onPostExecute 似乎没有被调用,并且 Activity 在从 doInBackground 返回时崩溃,LogCat 建议 nullPointerException 试图触发 Intent(在我开始弄乱 AsynchTask 之前我已经测试过并且工作正常)
知道为什么会这样吗?代码看起来很简单......
谢谢