在活动中设置ExpandableListView时出错 public class Official\u活动扩展活动{ 创建时的公共void(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.official_data2); setupViewComponent(); 新建setList().execute(); } 私有void setupViewComponent(){ //TODO自动生成的方法存根 ExpandableListView列表=(ExpandableListView)findViewById(R.id.list); } 私有类集合列表扩展了异步任务{ 列出小组; 列出儿童; final ProgressDialog progDlg3=新的ProgressDialog(正式组); 受保护的void onPreExecute(){ //TODO自动生成的方法存根 super.onPreExecute(); progDlg3.setTitle(“请稍候”); progDlg3.setMessage(“加载…”); progDlg3.setIcon(android.R.drawable.ic\u对话框\u信息); progDlg3.setCancelable(假); progDlg3.show(); } @凌驾 受保护列表doInBackground(无效…arg0){ //TODO自动生成的方法存根 列表newes=null; 试一试{ newes=GetJson.update(); 返回newes; }捕获(IOE异常){ //TODO自动生成的捕捉块 e、 printStackTrace(); }捕获(例外e){ //TODO自动生成的捕捉块 e、 printStackTrace(); } 返回newes; } 受保护的void onPostExecute(列表结果){ groups=newarraylist(); Map group1=新的HashMap(); 第1组put(“项目名称”、“地震报告”); 组1.put(“项目文本”,“来自美国地质调查局的数据”); Map group2=新的HashMap(); 第2组:put(“项目名称”、“天气信息”); 组2.放置(“项目文本”、“显示天气信息”); 添加(第1组); 添加(第2组); 列表数据=新的ArrayList(); for(新闻:结果){ HashMap项=新建HashMap(); item.put(“ItemTitle”,news.getPlace()); item.put(“ItemText”,“magnity:+news.getMag()); item.put(“latit”,news.getLatit()); item.put(“longit”,news.getLongit()); item.put(“date”,news.getTime()); item.put(“tzone”,news.getZone()); 数据。添加(项目); } List weather=new ArrayList(); HashMap item2=新的HashMap(); 项目2.put(“项目名称”、“即将推出”); 项目2.put(“项目文本”,下称“); 第2项:投入(“latit”); 第2项:投入(“长型”); 第2项:投入(“日期”); 第2项.付诸表决(“tzone”); 增加(第2项); childs=newarraylist(); 添加(数据); 添加(天气); ExpandableListAdapter mExpaListAdap=新的SimpleExpandableListAdapter( 这 组, R.layout.list_项目, 新字符串[]{“ItemTitle”,“ItemText”}, 新int[]{R.id.ItemTitle,R.id.ItemText}, 孩子们, R.layout.list\u地震, 新字符串[]{“ItemTitle”、“ItemText”、“latit”、“longit”、“date”、“tzone”}, 新int[]{R.id.ItemTitle,R.id.ItemText,R.id.latit,R.id.longit,R.id.date,R.id.tzone} ); list.setAdapter(mExpaListAdap); progDlg3.disclose(); } } }
但发现了错误:在活动中设置ExpandableListView时出错 public class Official\u活动扩展活动{ 创建时的公共void(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.official_data2); setupViewComponent(); 新建setList().execute(); } 私有void setupViewComponent(){ //TODO自动生成的方法存根 ExpandableListView列表=(ExpandableListView)findViewById(R.id.list); } 私有类集合列表扩展了异步任务{ 列出小组; 列出儿童; final ProgressDialog progDlg3=新的ProgressDialog(正式组); 受保护的void onPreExecute(){ //TODO自动生成的方法存根 super.onPreExecute(); progDlg3.setTitle(“请稍候”); progDlg3.setMessage(“加载…”); progDlg3.setIcon(android.R.drawable.ic\u对话框\u信息); progDlg3.setCancelable(假); progDlg3.show(); } @凌驾 受保护列表doInBackground(无效…arg0){ //TODO自动生成的方法存根 列表newes=null; 试一试{ newes=GetJson.update(); 返回newes; }捕获(IOE异常){ //TODO自动生成的捕捉块 e、 printStackTrace(); }捕获(例外e){ //TODO自动生成的捕捉块 e、 printStackTrace(); } 返回newes; } 受保护的void onPostExecute(列表结果){ groups=newarraylist(); Map group1=新的HashMap(); 第1组put(“项目名称”、“地震报告”); 组1.put(“项目文本”,“来自美国地质调查局的数据”); Map group2=新的HashMap(); 第2组:put(“项目名称”、“天气信息”); 组2.放置(“项目文本”、“显示天气信息”); 添加(第1组); 添加(第2组); 列表数据=新的ArrayList(); for(新闻:结果){ HashMap项=新建HashMap(); item.put(“ItemTitle”,news.getPlace()); item.put(“ItemText”,“magnity:+news.getMag()); item.put(“latit”,news.getLatit()); item.put(“longit”,news.getLongit()); item.put(“date”,news.getTime()); item.put(“tzone”,news.getZone()); 数据。添加(项目); } List weather=new ArrayList(); HashMap item2=新的HashMap(); 项目2.put(“项目名称”、“即将推出”); 项目2.put(“项目文本”,下称“); 第2项:投入(“latit”); 第2项:投入(“长型”); 第2项:投入(“日期”); 第2项.付诸表决(“tzone”); 增加(第2项); childs=newarraylist(); 添加(数据); 添加(天气); ExpandableListAdapter mExpaListAdap=新的SimpleExpandableListAdapter( 这 组, R.layout.list_项目, 新字符串[]{“ItemTitle”,“ItemText”}, 新int[]{R.id.ItemTitle,R.id.ItemText}, 孩子们, R.layout.list\u地震, 新字符串[]{“ItemTitle”、“ItemText”、“latit”、“longit”、“date”、“tzone”}, 新int[]{R.id.ItemTitle,R.id.ItemText,R.id.latit,R.id.longit,R.id.date,R.id.tzone} ); list.setAdapter(mExpaListAdap); progDlg3.disclose(); } } },android,android-listview,nullpointerexception,Android,Android Listview,Nullpointerexception,但发现了错误: public class Official_Activity extends Activity{ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.official_data2); setupViewComponent(); new setList().execu
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();
}
}
}
构造函数SimpleExpandableListAdapter(官方活动.setList,
列表,int,字符串[],int[],列表,
int,字符串[],int[])未定义
怎么解决呢?
getJson的代码:
9/8更新:
将“this”更改为“Official_Activity.this”后,发现另一个错误:
08-08 09:34:33.975:E/AndroidRuntime(335):java.lang.RuntimeException:无法启动活动组件信息{com.android.abc/com.android.abc.Official_activity}:java.lang.NullPointerException
代码中有任何错误吗?您在一个内部类中,因此“
此
”是官方活动。setList
类
,它不是上下文
,您必须编写官方活动。此
相反,如下所示:
The constructor SimpleExpandableListAdapter(Official_Activity.setList,
List<Map<String,Object>>, int, String[], int[], List<List<HashMap<String,Object>>>,
int, String[], int[]) is undefined
但是发现了另一个错误:08-08 09:34:33.975:E/AndroidRuntime(335):java.lang.RuntimeException:无法启动活动组件信息{com.android.abc/com.android.abc.Official_activity}:java.lang。NullPointerException@Hinata我需要异常发生的线路。你试过调试吗?(断点等)
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}
);