Skip to content Skip to sidebar Skip to footer

Mapfragment Findfragmentbyid Always Null

I have problems to access the fragment of the map. getFragmentManager().findFragmentById(R.id.map)) returns always null. I don't know why. What's the problem? Thank you!

Solution 1:

use this way:

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

            map = mapFrag.getMap();

here is full code with sample:

Solution 2:

In case your problem is not solved, try this :

As you are using SupportMapFragment, while retrieving map, use

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

Also, change

publicclassMapaextendsActivity {

to

publicclassMapaextendsFragmentActivity {

Solution 3:

I had a similar problem when trying to get MapFragment but getting null because the device didn't have Google Play Services updated.

Solution 4:

Change in the layout

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

by

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

Or, you can use getSupportFragmentManager() instead of getFragmentManager().

Post a Comment for "Mapfragment Findfragmentbyid Always Null"