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 のコード: 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" はOfficial_Activity.setList classではありません。代わりに、次のよう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 に答える