자답입니다.
SupportMapFragment.newInstance()를 한뒤 getMap()호출할 경우
아직 newInstance()를 하면서 GoogleMap객체 자체가 생성이 끝나지 않은 상태일 수도 있기 때문에 Null을 리턴 한다고 합니다.
따라서 해결 방법은 약간의 시간차이를 두고 getMap()함수를 호출하면 됩니다.
아래 코드와 같습니다.
mapFragment = SupportMapFragment.newInstance();
FragmentTransaction ft = getChildFragmentManager().beginTransaction();
ft.replace(R.id.mapview_layout, mapFragment, "map");
ft.commit();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
try{
googleMap = mapFragment.getMap();
}catch(NullPointerException e)
{
e.printStackTrace();
}
}
}, 3000);
-------------------------------------------------------------------------------원문 --------------------------------------------------------------------------
public final GoogleMap getMap ()
Gets the underlying GoogleMap that is tied to the view wrapped by this fragment.