我不知道这里有什么问题,因为我收到错误消息“执行 doInBackground() 时发生错误”任何帮助将不胜感激。我是异步的新手,如果我错了请解释。
private class childAsync extends AsyncTask<Void, Void, Void> {
private final ProgressDialog dialog = new ProgressDialog(
ChildClass.this);
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
dialog.setMessage("Loading...");
dialog.setIndeterminate(false);
dialog.show();
}
ArrayList<HashMap<String, String>> touchpoints = new ArrayList<HashMap<String, String>>();
@Override
protected Void doInBackground(Void... params) {
// Retrieve JSON Objects from the given string
try {
jsonObject = new JSONObject(JsonChildString); //testing data from JSON String
for (int i = 0; i < jsonArray.length(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
jsonObject = jsonArray.getJSONObject(i);
// Retrieve JSON Objects
map.put(TEXT, jsonObject.getString("text"));
map.put(ICON, jsonObject.getString("icon"));
// set the JOSN Objects into the array
touchpoints.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
listview = (ListView) findViewById(R.id.list_child);
// getting adapter by passing JSON data arrayList
adapter = new LazyAdapterNew(ChildClass.this, touchpoints);
listview.setAdapter(adapter);
dialog.dismiss();
}
}