android-layoutandroid-fragmentsxamarinandroid-fragmentactivityinflate-exception

Error inflating class fragment with class using FragmentActivity


I have coded a Google Maps application in Xamarin, and am getting this error:

Android.Views.InflateException: Binary XML file line #1: Error inflating class fragment

I am getting this error when the following line of code is run:

SetContentView(Resource.Layout.MapWithOverlayLayout);

Here is my MapWithOverlayLayout.axml layout file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
  <fragment class="SimpleMapDemo.MapWithMarkersActivity"
            android:id="@+id/mapWithOverlay"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
</LinearLayout>

The namespace is called: SimpleMapDemo

Here is my class declaration:

public class MapWithMarkersActivity : Android.Support.V4.App.FragmentActivity

I am using a SupportMapFragment object to display a Google Map

Can I please have some help to get this code working?


Solution

  • I have figured it out myself. I did not have the correct class name.

    Here is the correct layout code:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <fragment
            android:id="@+id/map"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            class="com.google.android.gms.maps.SupportMapFragment" />
    </LinearLayout>