0

我不知道这里有什么问题,因为我收到错误消息“执行 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();
    }

}
4

1 回答 1

0

我认为从 doInBackground() 返回类型为 void 但您正在返回

 ArrayList<HashMap<String,String>>

并在后期执行它的无效,但我认为它应该是

 onPostExecute(List<HashMap<String,String>> touchpoints) 

并更改 AsyncTask 声明

于 2013-07-17T05:20:55.990 回答