private void showResult() {
try {
JSONObject jsonObject = new JSONObject(mJsonString);
JSONArray jsonArray = jsonObject.getJSONArray(TAG_JSON);
int pictureResId = R.mipmap.ic_start;
HashMap<String, String> hashMap = new HashMap<>();
MarkerOptions friendMarker[] = new MarkerOptions[2];
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject item = jsonArray.getJSONObject(i);
String id = item.getString(TAG_ID);
String name = item.getString(TAG_NAME);
String longitude = item.getString(TAG_LONG);
String latitude = item.getString(TAG_LATI);
hashMap.put(TAG_NAME, name);
hashMap.put(TAG_LONG, longitude);
hashMap.put(TAG_LATI, latitude);
mArrayList.add(hashMap);
}
if (friendMarker1 == null) {
HashMap get = new HashMap();
double flongitude2;
double flatitude2;
for (int j = 0; j < mArrayList.size(); j++) {
//서버에서 gps위도 경도 받아오기
get = (HashMap)mArrayList.get(j);
String a = (String)get.get("latitude");
String b =(String)get.get("longitude");
Log.i(TAG, "제발: " + a + b);
flatitude2 = Double.parseDouble(a);
flongitude2 = Double.parseDouble(b);
Log.i(TAG, "위도: " + flatitude2 + flongitude2);
friendMarker[j].position(new LatLng(flatitude2,flongitude2));
friendMarker[j].title("친구 1\n");
friendMarker[j].icon(BitmapDescriptorFactory.fromResource(pictureResId));
map.addMarker(friendMarker[j]);
}
} else {
friendMarker1.position(new LatLng(3000, 3000));
}
} catch (JSONException e) {
Log.d(TAG, "showResult : ", e);
}
}
}
MarkerOptions를 사용하여 구글 지도에 friendMarker의 위치를 배열로 받아 서버에서 같은 schedule에 속한모든 친구들의 위치를 받아오려고 하는데 자꾸 배열에서 에러가 나네요
에러메시지는 java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.android.gms.maps.model.MarkerOptions com.google.android.gms.maps.model.MarkerOptions.position(com.google.android.gms.maps.model.LatLng)' on a null object reference 이렇습니다.
배열로 받아서 친구들 모든 위치를 띄우고 싶은데 어떻게 방법이 없을까요?? 도와주세요 부탁드립니다!!