我从下面的代码中得到一个例外:

int[] startApps;
JSONObject jsonObjectMapData=new JSONObject(result);
JSONArray jsonaryPlaceMark = jsonObjectMapData.getJSONArray("Apps");
JSONObject apps=   jsonaryPlaceMark.getJSONObject(0); int indx=0;
startApps[indx++]=Integer.parseInt(apps.getString("Thread1"));
startApps[indx++]=Integer.parseInt(apps.getString("Thread2"));


我在行上得到java.lang.NullPointerException:

          startApps[indx++]=Integer.parseInt(apps.getString("Thread1"));


服务器响应:

{
 "name": "10.000000,106.000000",
"Status": {
"code": 200,
"request": "geocode"
},
"Apps": [ {
"Thread1": 1,
"Thread2": 1,
"Thread3": 1,
"Thread4": 1,
"Thread5": 1,
"Thread6": 1,
"Thread7": 1
} ]
}

最佳答案

您没有初始化数组。

尝试:

int[] startApps;
startApps = int[10]; // or however big it needs to be


或执行以下步骤:

int[] startApps = int[10];

关于java - NullPointerException解析JSON对象,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15170874/

10-12 02:53