0

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

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
} ]
}
4

1 回答 1

4

你没有初始化你的数组。

尝试:

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

或者做一个步骤:

int[] startApps = int[10];
于 2013-03-02T05:01:03.887 回答