Binary XML file line #8: Error inflating class fragment, Google Maps

Try out below code:

public class ShowActivity extends android.support.v4.app.FragmentActivity {
    private GoogleMap mMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map);
        setUpMapIfNeeded();
    }

    @Override
    protected void onResume() {
        super.onResume();
        setUpMapIfNeeded();
    }

    private void setUpMapIfNeeded() {
        // Do a null check to confirm that we have not already instantiated the map.
        if (mMap == null) {
            // Try to obtain the map from the SupportMapFragment.
            mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                    .getMap();
            // Check if we were successful in obtaining the map.
            if (mMap != null) {
                setUpMap();
            }
        }
    }
}

XML file code:

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
       android:id="@+id/map"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       class="com.google.android.gms.maps.SupportMapFragment"/>

Manifest file code:

    <permission
        android:name="com.example.myfirstapp.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"/>
      <uses-permission android:name="com.example.myfirstapp.permission.MAPS_RECEIVE"/>
        <!-- Copied from Google Maps Library/AndroidManifest.xml. -->
      <uses-sdk
                android:minSdkVersion="8"
                android:targetSdkVersion="16"/>
        <uses-permission android:name="android.permission.INTERNET"/>
      <uses-permission         android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- External storage for caching. -->
       <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
      <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>
      <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >    
         <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="removed" />
   </application>

I am trying to deploy Google Play Services V2 (for Google Map functionalities) on Android 2.3.4. (API level 10), I had the same problem. Here is how I solved it:

  1. google-play-services_lib had to be included as a library. In Eclipse, you can do this as follows:

    • Use the Android SDK Manager to download the library.
    • Create a new Android Project from existing code where you point to google-play-services_lib in the folder you used to install the SDK. I used one level up (libproject).
    • Under Project -> Properties -> Android flag this project as Is library.
    • In your project, also open Project -> Properties -> Android and click on Add in the library section. Select the google-play-services_lib. It will appear as com_google_android_gms.

    This is important: please ensure the project build target for the library is the same as the one used for your app.

  2. Because the API version is beneath 11, SupportMapFragment is used instead of MapFragment.

Hope this helps. It has taken me at least three solid hours to work this one out.


I followed the below steps::

Step 1: Include below line in manifest make sure you add within the application tag

    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyA0YQoByyHKGbB2R3pSIerQCEiGlwieRas" />
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

Ex::

 <application
        android:name="taxialways.user.MyApplication"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name="taxialways.user.Register"
            android:label="@string/title_activity_register"
            android:noHistory="true"
            android:screenOrientation="portrait" >
        </activity>

        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyA0YQoByyHKGbB2R3pSIerQCEiGlwieRas" />
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
</application>

Step 2: Make sure your activity extends FragmentActivity


Step 3: Use the mapFragment element as below in the xml

  <fragment
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:layout_alignParentBottom="true"
    android:layout_below="@+id/lineartab" />