a=new String[]{"班","云","学","学","教","考","结","加"}; b=new String[]{"无","未","上","暂","暂","暂","","允"}; List<Map<String,Object>> mapList2=new ArrayList<Map<String,Object>>(); for(int j=0;j<8;j++){ Map<String,Object> listitem2=new HashMap<String,Object>(); listitem2.put("a",a[j]); listitem2.put("b",b[j]); mapList2.add(listitem2); } SimpleAdapter adapter2=new SimpleAdapter(this,mapList2,R.layout.item3,new String[]{"a","b"},new int[]{R.id.textView10,R.id.textView11}); listView2.setAdapter(adapter);错哪了
时间: 2023-07-19 08:11:01 浏览: 92
这段代码中存在以下问题:
1. `b` 数组中第七个元素为空字符串,应该改为 `"暂"` 或者其他非空字符串。
2. 在创建 `SimpleAdapter` 对象时,使用了错误的参数 `adapter`,应该改为 `adapter2`。
修改后的代码如下:
```
a = new String[]{"班", "云", "学", "学", "教", "考", "结", "加"};
b = new String[]{"无", "未", "上", "暂", "暂", "暂", "暂", "允"};
List<Map<String,Object>> mapList2 = new ArrayList<Map<String,Object>>();
for(int j = 0; j < 8; j++) {
Map<String,Object> listitem2 = new HashMap<String,Object>();
listitem2.put("a", a[j]);
listitem2.put("b", b[j]);
mapList2.add(listitem2);
}
SimpleAdapter adapter2 = new SimpleAdapter(this, mapList2, R.layout.item3, new String[]{"a", "b"}, new int[]{R.id.textView10, R.id.textView11});
listView2.setAdapter(adapter2);
```
阅读全文