我想显示这个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