1
I’m trying to put a mark on the map and it’s making a mistake NullPointExeption
Follows the method:
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();
}
}
Error occurs on line:
mapa = SupportMapFragment.newInstance(new GoogleMapOptions().zOrderOnTop(true)).getMap();
It would be nice if you highlight the line where nullPointerException error occurs, so that people can help you more easily.
– Caputo
Opa, foi malz ae. The error ta on the line: map = Supportmapfragment.newInstance(new Googlemapoptions().zOrderOnTop(true)). getMap();
– lucas_marciano
When I take this line the system runs smoothly, I just wanted to better understand what it is for, since this stretch I took straight from the Google site and there I found no details on this particular line.
– lucas_marciano