Binary XML file line #2: Error inflating class fragment
android, android-fragments, google-maps, xml
Solution
First you need to move `<meta-data>` tag under `<application>` tag in your `manifest.xml`.
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
and your minsdk="8" so you should change this
public class MainActivity extends Activity
to
public class MainActivity extends FragmentActivity
and also change this
<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.MapFragment"/>
to
<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"/>
Problem
I'm trying to add a map in a project but I cannot because there is some error when I debug the application with the fragment. This is my XML file: ``` <?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" class="com.google.android.gms.maps.MapFragment"/> ``` This is my .java file: ``` import android.os.Bundle; import android.app.Activity; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } } ``` And, This is my Manifest: ``` <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.inkadroid.mapa" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" /> <uses-feature android:glEsVersion="0x00020000" android:required="true"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name = ".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="My_KEY"/> </application> </manifest> ``` Also, I've added google_play_services library. Visit http://i61.tinypic.com/2jdjaky.jpg And, I get this error. If anyone know how to solve it, please tell me. ``` 06-02 22:21:50.615: E/AndroidRuntime(869): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.inkadroid.mapa/com.inkadroid.mapa.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment 06-02 22:21:50.615: E/AndroidRuntime(869): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) 06-02 22:21:50.615: E/AndroidRuntime(869): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) ```