的Hashmap值当我创建这个对象,我这样做:访问数组列表中
random_fields= new ArrayList<HashMap<String, String>>();
try {
// Getting Array of fields
JSONArray fields= json.getJSONArray("fields");
// Looping through All fields
for(int i = 0; i < fields.length(); i++) {
JSONObject jobj = fields.getJSONObject(i);
// Creating new HashMap
HashMap<String, String> map_aux = new HashMap<String, String>();
// Adding each child node to HashMap key => value
map_aux.put("field_id", jobj.getString("field_id"));
map_aux.put("field_text", jobj.getString("field_text"));
}
// Adding HashList to ArrayList
random_fields.add(map_aux);
}
,然后当我尝试进入的每一个领域中包含HashMap的ArrayList中......我喜欢这:
例如:
editText1.setText(random_fields.get(0).get("field_text"));
,它给了我一个Java空指针错误......但如果我这样做:
System.out.println(random_challenges.get(0).get("field_text"));
它的工作原理和它打印在我的调试控制台..正确的字段..哪个可以解决方案?
请花更多精力来设置您的帖子格式。你应该已经能够从预览中看到你的代码是*英里*在右边,无故滚动。此外,请使用空格而不是制表符在Stack Overflow上进行缩进。 – 2014-10-01 13:36:24
你用'random_fields'设置文本但打印'random_challenges'? – 2014-10-01 13:38:25
确保你的程序不会抛出异常。如果抛出,可能是'random_fields.get(0).get(“field_text”)= null' – 2014-10-01 13:43:46