我想顯示這個JSON數據進入列表視圖。有蔭這個問題:NullPointerException與Android上的列表視圖
java.lang.NullPointerException: Attempt to invoke virtual method 'org.json.JSONObject org.json.JSONArray.getJSONObject(int)' on a null object reference
private String[] arrow() throws JSONException {
json = new JSONObject();
JSONArray com= null;
String[] list = new String[10];
try {
com = json.getJSONArray("parameters"); // this have 10 different values
} catch (JSONException e) {
e.printStackTrace();
}
for (int i = 0; i < 10; i++)
try {
json = com.getJSONObject(i);
String forward= json.getString("forward");
String back= json.getString("back");
list[i]="Forward: " + forward + "\n" + "Backward: " + back;
} catch (JSONException e) {
e.printStackTrace();
}
return list;
}
我的TextView做到了,但不能用列表視圖做到這一點,我得到這個空指針.. 請幫助。謝謝。
第一個'e.printStackTrace()'是否打印任何東西? – immibis
不,不這麼認爲 – RightOn