Android 안드로이드2014. 12. 5. 00:05


최신 버전 구글 맵은 프로그래먼트를 사용해서 표시된다. 구글맵 프래그먼트를 붙여놓은 초기 상태에서 에러없이 실행된다. 레이아웃을 바꾸고자 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) 파일에서 각종 뷰 요소나 중첩레이아웃 요소를 


구글맵 api키 (Google Map API KEY )가 정상작동하나?
==> 두말하면 잔소리다. 이미 지도는 잘 나왔다. 디자인 변경이 안될 뿐이다.


mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

아래와 같이 사용해보라고 

FragmentManager myFM = getActivity().getSupportFragmentManager();
final SupportMapFragment myMAPF = (SupportMapFragment) myFM
                .findFragmentById(R.id.map);
==> 아직 프로요나 진저 등 하위 버전까지 지원하기에는 벅차다. 이제 시작이다.


지금 어제부터 정답을 찾아 헤매고 있는중이다. 더 정확히는 몇일 전에도 만졌다. 조금씩 뷰 구성 요소를 이동시키고 단말기와 에물레이터로 에러있나 없나를 확인하면서 레이아웃을 얼쭈변경했다. 이렇게 해서 앞으로도 있을 무수한 같은 작업을 인내할 수는 없는 노릇이다. 그래서 지금 이러고 있다. 

내 생각에 답은 구글맵에 없다. 프래그먼트에 있다고 본다. 이 부분을 입맛에 맛게 제단하려면 fragment를 파고들어야한다. 아래 링크에 보면 나의 눈에만 띄는 구절을 누군가가 달아놓았다. 직접 해결책은 아닌데 이 길로 적어놨다. 나도 그렇게 생각한다. 
http://stackoverflow.com/questions/24947483/google-maps-apiv2-app-not-working-keeps-crashing


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.





http://developer.android.com/guide/components/fragments.html
http://developer.android.com/training/location/index.html




Posted by 코드버무려