Forum Xamarin Xamarin.Android

SupportMapFragment return NULL

The method below creates the map to be displayed in the app fragment. But it is returning NULL.

axml file:
<?xml version="1.0" encoding="utf-8"?> <fragment xmlns:android="" android:id="@+id/mapGoolgle" android:layout_width="wrap_content" android:layout_height="wrap_content" class="" />


` public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
View v = base.OnCreateView(inflater,container,savedInstanceState);


        return v;

private void initMap(){

        _mapFragment = (SupportMapFragment) FragmentManager.FindFragmentById (Resource.Id.mapGoolgle);  //return null

        _googleMap = _mapFragment.Map;

        _googleMap.MyLocationEnabled = true;

        _googleMap.MapType = GoogleMap.MapTypeNormal;
    } `

I make sure the service is running and is ok:

` public bool IsOk()
int resultCode = GooglePlayServicesUtil.IsGooglePlayServicesAvailable (mainActivity);

        if(resultCode != ConnectionResult.Success)
            return false;
        } else {
            return true;
    } `


  • CheesebaronCheesebaron DKInsider, University mod

    You can cast it like that you have to use JavaCast<T>().

    _mapFragment = FragmentManager.FindFragmentById (Resource.Id.mapGoolgle).JavaCast<SupportMapFragment>();

    Also if you are using SupportMapFragment you also want to use SupportFragmentManager.

    Also you are not inflating your view. Use the LayoutInflater that is provided to you:

    var view = inflater.Inflate(Resource.Layout.layoutName, container, false);
Sign In or Register to comment.