0
我得到NullPointerException運行此代碼: 我不知道我做了什麼來觸發此異常。 在try-catch語句之前沒有問題。 logcat還會在代碼的placesOverlay部分顯示錯誤。Android:OverlayItem導致null
private OverlayItem[] placesOverlay;
ArrayList<Places> arrPlace = new ArrayList<Places>();
.
//other codes
.
.
JSONArray jArray = new JSONArray(response);
for(int i = 0; i < jArray.length() ; i++)
{
Places place = new Places();
JSONObject jObj = jArray.getJSONObject(i);
place.setPlace(
jObj.optString("placeID"),
jObj.optString("placeName"),
jObj.optString("placeType"),
jObj.optString("placeLat"),
jObj.optString("placeLng"),
jObj.optString("placePict"),
jObj.optString("placeRegion"));
arrPlace.add(place);
try{
placesOverlay[i] = new OverlayItem(
new GeoPoint(
(int)(Double.parseDouble(arrPlace.get(i).getLat())*1E6),
(int)(Double.parseDouble(arrPlace.get(i).getLng())*1E6)),
arrPlace.get(i).getPlaceName(),
arrPlace.get(i).getType());
}catch(Exception ex){
Log.e("log_g",""+ex.getMessage());
}
logcat的:
02-22 18:40:27.985: E/log_g(9909): null
02-22 18:40:27.985: E/log_g(9909): null
02-22 18:40:27.985: E/log_g(9909): null
02-22 18:40:27.985: E/log_g(9909): null