Search code examples
javaandroidbinarygoogle-maps-android-api-2layout-inflater

Binary XML file line #2: Error inflating class


I know similar questions like this has been answered but I seem to have done what the tutorial suggested and reading from other posts but still I get the Inflator error. Not sure what I am doing wrong. I don't see Google-Map. Please check the code. Thanks a lot.

I generate My Key with:

keytool -list -v -keystore mystore.keystore

Activity_Map.java

package pt.example.project;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

public class Activity_Map extends FragmentActivity {

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

filexml.xml

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

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pt.example.project"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<!-- START COPY DEV GOOGLE DOCS -->
<permission
    android:name="pt.example.project.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<uses-permission android:name="pt.example.project.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!--
 The following two permissions are not required to use
 Google Maps Android API v2, but are recommended.

-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />
<!-- END COPY DEV GOOGLE DOCS -->

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/generalnotitle" >
    <uses-library android:name="com.google.android.maps" />

    <activity
        android:name="pt.example.project.MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="pt.example.project.Activity_Mapa"
        android:label="@string/title_activity__mapa"
        android:theme="@android:style/Theme.NoTitleBar">
    </activity>

    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="My KEY" />
</application>


Solution

  •     android:minSdkVersion="8"
    

    Your min sdk is 8 you need to add support library or make your min sdk to 12

    http://developer.android.com/tools/extras/support-library.html

    Use SupportFragment.

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

    Quoting from the docs

    Use MapFrament class only if you are targeting API 12 and above. Otherwise, use SupportMapFragment.

    For more Information check the link

    https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/MapFragment