Google Map Marker Error v2

1

I'm trying to put a tag on the map and it's giving an error of NullPointExeption

The method follows:

private void setMapaGoogle() {
    if (mapa != null) {
        mapa = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
        try{
            LatLng latlng = new LatLng(latitude,longitude);
            **mapa = SupportMapFragment.newInstance(new GoogleMapOptions().zOrderOnTop(true)).getMap();**
            mapa.addMarker(new MarkerOptions()
                    .position(latlng)
                    .title("Onde Estou!")
                    .snippet("")
                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.mark_mapa_local_atual))
                    .visible(true));
            // Move a camera para a posição.
            mapa.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude,longitude),14));
            //Efeito na camera do mapa
            mapa.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
            mapa.getUiSettings().setZoomControlsEnabled(false);
            mapa.getUiSettings().setCompassEnabled(false);
            mapa.getUiSettings().setMyLocationButtonEnabled(false);
       } catch (Exception e) {
           StringBuilder sb = new  StringBuilder().append(e.getClass().getSimpleName()); 
           if  (e.getMessage() != null) { 
               sb.append("\n"); 
               sb.append(e.getMessage()); 
           } 
           Log.e("Exeção", sb.toString()); 
           aux = sb.toString();
           // this code write out all message
           Log.e("Exeção","setMapaGoogle", e);
       }
    }else{
        setMapaGoogle();
    }
}

The error occurs on the line:

mapa = SupportMapFragment.newInstance(new GoogleMapOptions().zOrderOnTop(true)).getMap(); 
    
asked by anonymous 05.05.2014 / 22:02

1 answer

2

It is possible that this happens because in your XML file you have:

  

android: name="com.google.android.gms.maps.MapFragment"

change in java from

 mapa = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();      

for

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

(without the **)

or in the xml of

  

android: name="com.google.android.gms.maps.MapFragment"

for

  

android: name="com.google.android.gms.maps.SupportMapFragment"

You have to be careful when referencing something. It says something if I helped and if this is even the mistake :) If it is not try to put here the logcat and the xml file too!

Cumps

    
08.05.2014 / 01:20