0
    public class Official_Activity extends Activity{
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.official_data2);
    setupViewComponent();

    new setList().execute();
}

 private void setupViewComponent() {
    // TODO Auto-generated method stub
     ExpandableListView list = (ExpandableListView)findViewById(R.id.list);
}

private class setList extends AsyncTask <Void, Void, List<News>>{

    List<Map<String, Object>> groups;
    List<List<HashMap<String, Object>>> childs;




     final ProgressDialog progDlg3 = new ProgressDialog(Official_Group.group);


    protected void onPreExecute() {
        // TODO Auto-generated method stub
        super.onPreExecute();
        progDlg3.setTitle("Please wait");
        progDlg3.setMessage("Loading...");
        progDlg3.setIcon(android.R.drawable.ic_dialog_info);
        progDlg3.setCancelable(false);
        progDlg3.show();
    }

    @Override
    protected List<News> doInBackground(Void... arg0) {
        // TODO Auto-generated method stub
        List<News> newes = null;
        try {
            newes = GetJson.update();
            return newes;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return newes;


    }

    protected void onPostExecute(List<News> result){

         groups = new ArrayList<Map<String, Object>>();
        Map<String, Object> group1 = new HashMap<String, Object>();
        group1.put("ItemTitle", "Earthquake report");
        group1.put("ItemText", "Data from USGS");
        Map<String, Object> group2 = new HashMap<String, Object>();
        group2.put("ItemTitle", "Weather info");
        group2.put("ItemText", "Show weather info");
    groups.add(group1);
    groups.add(group2);

    List<HashMap<String, Object>> data = new ArrayList<HashMap<String, Object>>();
    for(News news : result){
        HashMap<String, Object> item = new HashMap<String, Object>();
        item.put("ItemTitle", news.getPlace());
        item.put("ItemText", "Magnitude: "+news.getMag());
        item.put("latit", news.getLatit());
        item.put("longit", news.getLongit());
        item.put("date", news.getTime());
        item.put("tzone", news.getTzone());
        data.add(item);
    }

List<HashMap<String, Object>> weather = new ArrayList<HashMap<String, Object>>();
    HashMap<String, Object> item2 = new HashMap<String, Object>();
    item2.put("ItemTitle", "Coming Soon");
    item2.put("ItemText", "");
    item2.put("latit", "");
    item2.put("longit", "");
    item2.put("date", "");
    item2.put("tzone", "");
    weather.add(item2);

     childs = new ArrayList<List<HashMap<String, Object>>>();
    childs.add(data);
    childs.add(weather);

    ExpandableListAdapter mExpaListAdap = new SimpleExpandableListAdapter(
            this,
            groups,
            R.layout.list_item,
            new String[] {"ItemTitle", "ItemText"},                   
            new int[] {R.id.ItemTitle, R.id.ItemText},
            childs,                                     
            R.layout.list_earthquake,
            new String[] {"ItemTitle", "ItemText", "latit", "longit", "date", "tzone"},
            new int[] {R.id.ItemTitle, R.id.ItemText, R.id.latit, R.id.longit, R.id.date, R.id.tzone}
            );

        list.setAdapter(mExpaListAdap);
      progDlg3.dismiss();     
    }



 }
   }

但是发现错误:

The constructor SimpleExpandableListAdapter(Official_Activity.setList,
List<Map<String,Object>>, int, String[], int[], List<List<HashMap<String,Object>>>,
int, String[], int[]) is undefined

如何解决?

getJson 的代码:Intent 与 ListView(JSON 数据)

9/8 更新:我将“this”更改为“Official_Activity.this”后,发现另一个错误:

08-08 09:34:33.975: E/AndroidRuntime(335): java.lang.RuntimeException: 无法启动活动 ComponentInfo{com.android.abc/com.android.abc.Official_Activity}: java.lang.NullPointerException

代码中是否有任何错误?

4

1 回答 1

1

你在一个内部类中,所以 " this" is Official_Activity.setList class,它不是 a context,你必须改写Official_Activity.this,如下所示:

new SimpleExpandableListAdapter(
            Official_Activity.this,
            groups,
            R.layout.list_item,
            new String[] {"ItemTitle", "ItemText"},                   
            new int[] {R.id.ItemTitle, R.id.ItemText},
            childs,                                     
            R.layout.list_earthquake,
            new String[] {"ItemTitle", "ItemText", "latit", "longit", "date", "tzone"},
            new int[] {R.id.ItemTitle, R.id.ItemText, R.id.latit, R.id.longit, R.id.date, R.id.tzone}
            );
于 2012-08-08T09:15:13.713 回答