Google Maps v2中的getMap出错

时间:2014-01-24 10:08:42

标签: android google-maps android-maps-v2

我正在使用google maps v2 API,当我要使用getMap方法获取地图时,它会返回此错误:

01-24 10:56:25.164: E/AndroidRuntime(2488): FATAL EXCEPTION: main
01-24 10:56:25.164: E/AndroidRuntime(2488): java.lang.NullPointerException
01-24 10:56:25.164: E/AndroidRuntime(2488):     at .MapaFragment.onCreateView(MapaFragment.java:47)

我需要在片段类中获取地图,这是我的碎片类:

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMapClickListener;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;
import com.insoftcan.diinv2.api.ListaLugares;

public class MapaFragment extends Fragment implements OnMapClickListener {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    if (container != null) {
        container.removeAllViews();
    }

    rootView = inflater.inflate(R.layout.fragment_mapa, container, false);

    // Get map    
    GoogleMap mMap = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map)).getMap();

    return rootView;
}

我的布局是这样的:

<fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment"
    android:gravity="center" />

0 个答案:

没有答案