Hello Google Maps Example NULL Pointer Exception
Date : March 29 2020, 07:55 AM
|
Android Google map Null pointer exception when adding marker
Tag : java , By : alexmajy
Date : March 29 2020, 07:55 AM
wish of those help I do not see where you assign userIcon any value, and therefore BitmapDescriptorFactory.fromResource(userIcon) might be returning null as a result.
|
Null pointer exception in android google maps
Date : March 29 2020, 07:55 AM
help you fix your problem It may be due to play service issue. So null check map object before using map so it will automatically ask to download map in device. please try and reply @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
if(map!=null){
Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
.title("Hamburg"));
Marker kiel = map.addMarker(new MarkerOptions()
.position(KIEL)
.title("Kiel")
.snippet("Kiel is cool")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));
// Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
}
|
Programmatically Creating MapView and Adding a Marker Results in a null pointer exception in the fragment
Date : March 29 2020, 07:55 AM
I hope this helps you . because your googleMap is not loaded yet means null and you are adding marker on it which is causing a crash. better to use mapView.getMapAsync(context); rather than mapView.getMap(); and implement this method @Override
public void onMapReady(final GoogleMap map) {
if(map != null){
// you are ready to add marker here
}
}
|
Google maps - null pointer exception
Date : March 29 2020, 07:55 AM
will help you I've already tried the previously mentioned solutions. , Initialize googleMap inside onMapReady @Override
public void onMapReady(GoogleMap map) {
googleMap = map;
map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
map.setMyLocationEnabled(true);
map.setTrafficEnabled(true);
map.setIndoorEnabled(true);
map.setBuildingsEnabled(true);
map.getUiSettings().setZoomControlsEnabled(true);
}
|