Nullpointerexception from Google Maps

google maps are returning null pointer exception

You have to wait until map getting loaded....

public class ChatFragment extends Fragment implements OnMapReadyCallback {

private void initilizeMap() {
//SupportMapFragment mapFragment = (SupportMapFragment) fragmentManager.findFragmentById(R.id.map);

SupportMapFragment mapFrag = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);
mapFrag.getMapAsync(this);
}

@Override
public void onMapReady(final GoogleMap map) {
googleMap = map;
//Do other stuff..........
}

}

Edit

SupportMapFragment mapFrag = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);

Check the edit code, use ChildFragmentManager.

Google Map returning nullpointerexception Google Maps Android V2

googleMap = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map)).getMap();

This worked for me. getSupportFragmentManager() seemed to be causing all the crashes.

Null pointer exception in android google maps

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

Google maps - null pointer exception

Initialize googleMap inside onMapReady

googleMap = map;

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

Google maps crash: java.lang.NullPointerException: Attempt to read from null array

Ok, so I opened a ticket on google issue tracker and a lot of people confirmed they were facing the same crash.

Seems like an internal bug ticket was created and the work is being done to resolve the issue on maps side.
Also a temporary workaround was suggested in comments:

The workaround, that worked for me is to set maxZoomPreference on the
map equal to 16 and to use 16 as zoom level in the calling of the
newLatLngZoom method. It seems that the issue occurs only when you try
to zoom more than 16 levels.

We implemented the suggested approach in our app and it indeed prevents the crash.

Upd:

According to Google the crash was fixed for future SDK versions.

Upon further checking, our Engineering Team was able to reproduce the
problem and already fixed it in the latest SDK version.

NullPointerException from Google maps

So as suspected this is an issue at googles side. They've verified the bug and are working on a fix (2015-12-21), see googles bug tracker for up to date info about the issue.

Edit:

So I got to test Georges SD info and yes inserting a SD card solved the problem. So from this we can conclude phones that don't have an internal fake-external storage (like most phones now a days) will crash from this bug... So this might be a workaround for those who work in the enterprise segment but for those working in the consumer segment this will not really help a lot...

Edit Jan 20, 2016

A developer from the Google team has announced the fix has been made and it will be rolled out with the next major release of Google play, but they haven't set a timeline for that yet.

Edit Jun 02, 2016

A developer from the Google team has announced it is confirmed fixed:

Sorry this took so long to fix, but here is the bug fix you've been
waiting for!

We can confirm that this issue is now fixed in version 9.0.83 of
Google Play Services, released in May 2016.

NullPointerException When Trying to place Marker on Google Map V2

After 3 Days Searching and Working on it here is what finally worked.the real problem is googlemap is null which means map is not loaded.I used try and catch but You should never just catch and exception and do nothing.
after Log the exceptions, check the logs I found this:

com.google.android.gms.maps.MapFragment.getMap()' on a null object reference

First I tried This link Google Map returning nullpointerexception Google Maps Android V2

googleMap = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map)).getMap();

Then getChildFragmentManager become red indicating getChildFragmentManager () cannot be resolved or cannot be referenced.using getSupportFragmentManager() instead as described in this link
(getChildFragmentManager () cannot be resolved or cannot be referenced) finally solved the problem and map has been loaded

googlemap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapfragment)).getMap();

Note that if your class extends from AppCompatActivitythen You need to use getSupportFragmentManager()
because getChildFragmentManager() is a method of a Fragment not accessible fromAppCompatActivity

java.lang.NullPointerException: MapFragment.getMapAsync(com.google.android.gms.maps.OnMapReadyCallback)

I am sorry for that it is all about my stupid fault .

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); ----->it should be activity_maps



Related Topics



Leave a reply



Submit