Mapfragment findFragmentById always null

I have problems to access the fragment of the map.
getFragmentManager().findFragmentById( returns always null.
I don’t know why.
What’s the problem?

Thank you!

  • How to add ripple effect to preferences in android?
  • About “init: untracked pid xxxx exited” in Genymotion
  • android - GC_FOR_ALLOC freed 6346K, 7% free , paused 143ms, total 143ms
  • Android: disable ListView selection
  • Constant string parameters and the Delphi XE5 compiler for Android
  • Changing Orientation, losing all my list items
  • <LinearLayout xmlns:android=""
        android:orientation="vertical" >
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge" />
                android:tag="tag_fragment_map" />

    And in the activity after the setContentView I try to access to the map, but I receive an exception

    public class Mapa extends Activity {
    private GoogleMap mMap;
    private ActionBar ab;
    private TextView tvNombreCentro;
    private TextView tvTelefonoValor;
    private TextView tvEMailValor;
    private TextView tvWebValor;
    private TextView tvDireccionValor;
    public void onCreate(Bundle savedInstanceState) {
        GoogleMap mMap = ((MapFragment) getFragmentManager().findFragmentById(

    Related posts:

    How to list all the files in android phone by using adb shell?
    How to give hexagon shape to ImageView
    Need an example of HttpResponseCache in Android
    How to write files to assets folder or raw folder in android?
    android: webview inside dialog or popup
    Imported module in Android Studio can&#039;t find imported class
  • Eclipse ADT Unexpected exception 'Cannot run program'
  • Avoiding content type issues when downloading a file via browser on Android
  • SyncAdapter always in pending state
  • Android separate string values for release and debug builds
  • How to set the preview image in videoview before playing
  • WebView Display White or Blank page
  • 4 Solutions collect form web for “Mapfragment findFragmentById always null”

    use this way:

    SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager()
                map = mapFrag.getMap();

    here is full code with sample:

    In case your problem is not solved, try this :

    As you are using SupportMapFragment, while retrieving map, use

       GoogleMap mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(;

    Also, change

       public class Mapa extends Activity {


       public class Mapa extends FragmentActivity {

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

    Change in the layout

    android:name = ""


    android:name = "".

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

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.