0

I'm using the google maps v2 API and when I going to get the map with the getMap method it returns this error:

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)

I need to get the map within a fragment class, this is my fragmen class:

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;
}

And my layout is this:

<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" />
Yeray
  • 1,265
  • 1
  • 11
  • 23

0 Answers0