최신 버전 구글 맵은 프로그래먼트를 사용해서 표시된다. 구글맵 프래그먼트를 붙여놓은 초기 상태에서 에러없이 실행된다. 레이아웃을 바꾸고자 layout폴더에서 activity_mainmapmap.xml를 수정했다.
뷰 위치를 조금 변경했다.
오류가 틔어나왔다.
되돌리기해서 내부 중첩 LinearLayout의 위치를 바꿨다.
역시 오류가 나왔다.
Button위치를 바꿨다.
오류
TextView
에러
.
.
.
.
이쪽에서는 잘 쓰는 단어가 있다.
무한반복.
감으로 fragment에 문제가 있을 것이라!
디버그를 돌렸더니
mcGoogleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map_google)).getMap();
에서 mcGoogleMap가 null값을 받는다.
관련한 에러가 주르륵 뜨는데 googlemap fragment에 해당하는 부분만 복사해서 아래에 붙여놓았다.
12-05 16:48:21.070: E/AndroidRuntime(7241): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mapmmap/com.example.mapmmap.GPSInfo}: java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.android.gms.maps.GoogleMap com.google.android.gms.maps.MapFragment.getMap()' on a null object reference
구글링(googling)을 해보면 많은 답변이 나온다. 보통 때와 같이 다 쓸데 없는 답변이다.
http://stackoverflow.com/questions/13722192/google-maps-android-api-v2-throws-googleplayservicesnotavailableexception-out-o
https://code.google.com/p/android-developer-preview/issues/detail?id=1947
http://android-er.blogspot.in/2012/12/a-simple-example-using-google-maps.html
http://stackoverflow.com/questions/21569716/nullpointerexception-for-googlemap-object
구글서비스플레이(Google Play Services)가 설치되었나?
==> 당연설치되어있다. 이미 구글 지도는 잘 뜬다. 요소변경 다시 말해 레이아웃 변경이 안될 뿐이다. 그러니 xml 레이아웃(layout) 파일에서 각종 뷰 요소나 중첩레이아웃 요소를
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
를 아래와 같이 사용해보라고
FragmentManager myFM = getActivity().getSupportFragmentManager();
final SupportMapFragment myMAPF = (SupportMapFragment) myFM
.findFragmentById(R.id.map);
public final GoogleMap getMap ()
Gets the underlying GoogleMap that is tied to the view wrapped by this fragment.
Returns the GoogleMap. Null if the view of the fragment is not yet ready. This can happen if the fragment lifecyle have not gone through onCreateView(LayoutInflater, ViewGroup, Bundle) yet. This can also happen if Google Play services is not available. If Google Play services becomes available afterwards and the fragment have gone through onCreateView(LayoutInflater, ViewGroup, Bundle), calling this method again will initialize and return the GoogleMap.
'Android 안드로이드' 카테고리의 다른 글
ArrayList 요소 모두 제거 (0) | 2014.12.15 |
---|---|
Parcelable 객체 만들기 (0) | 2014.12.06 |
Call requires API level 5 (current min is 3): (0) | 2014.12.04 |
이클립스 단축키, 안드로이드 AVD 단축키 (0) | 2014.12.04 |
Dialog 대화상자 만들기 두 가지 (0) | 2014.12.02 |