的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