帮助从ArrayList
获取值data = new ArrayList<Map<String, String>>();
for (int i = 0; i < marks.length; i++) {
HashMap<String, String> m = new HashMap<String, String>();
m.put("title", marks[i].getUserName());
m.put("mark", marks[i].getMark().toString());
m.put("type", marks[i].getType().toString());
m.put("description", marks[i].getDescription());
data.add(m);
}
尝试从适配器中取出一个ArrayList并将值写入数组:
data = simpleAdapter.getData();
MarksRead[] marksReads = new MarksRead[data.size()];
for (int i = 0; i < data.size(); i++) {
marksReads[i].setDescription(data(i).get("description"));
marksReads[i].setMark(Integer.valueOf(data.get(i).get("mark")));
marksReads[i].setType(Integer.valueOf(data.get(i).get("type")));
}
在线marksReads[i].setDescription(data(i).get("description"));
输出为Exception NullPointerException.
帮助,如何正确行事。
答案 0 :(得分:6)
您必须先创建对象才能使用它
for (int i = 0; i < data.size(); i++) {
marksReads[i] = new MarksReads();
marksReads[i].setDescription(data(i).get("description"));
marksReads[i].setMark(Integer.valueOf(data.get(i).get("mark")));
marksReads[i].setType(Integer.valueOf(data.get(i).get("type")));
}