title: Google Maps API Level 2 - Sample Code - Android Studio
body: <p>I am trying to run the sample Google Maps Android API v2 found on this <a href="https://developers.google.com/maps/documentation/android/start" rel="nofollow">page</a> in Android Studio. </p>
  
  <p>My question is why am I getting the <code>android.view.InflateException: Binary XML file line #2: Error inflating class fragment</code> shown in the logcat below?</p>
  
  <p>Environment:
  IDE: Android Studio 1.0.1
  Device: Galaxy Nexus, Android version 4.2.1</p>
  
  <p>I have at looked at the related questions and tried the suggested solutions, but nothing has worked. </p>
  
  <p>Most of the other question were using a <code>FragmentActivity</code> and needed a <code>SupportMapFragment</code> but I am using a regular <code>Activity</code> and <code>MapFragment</code> as shown in the example on the web page. I am using a minimum API level of 15 so I thought the <code>FragmentActivity</code> and  <code>SupportMapFragment</code> were not necessary.</p>
  
  <p>I have copied the example code directly from the web <a href="https://developers.google.com/maps/documentation/android/start" rel="nofollow">page</a>.</p>
  
  <p>The error from the logcat. (Only included the first bit.)</p>
  
  <pre><code>02-12 19:59:49.496  23891-23891/edu.utexas.scottm.googlemapsapi_2_demo E/AndroidRuntime﹕ FATAL EXCEPTION: main
      java.lang.RuntimeException: Unable to start activity ComponentInfo{edu.utexas.scottm.googlemapsapi_2_demo/edu.utexas.scottm.googlemapsapi_2_demo.SimpleMapActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
  </code></pre>
  
  <p>The layout file activity_simple_map.xml (copied from the web page cited)</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;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"/&gt;
  </code></pre>
  
  <p>The Activity (copied from the web page cited)</p>
  
  <pre><code>package edu.utexas.scottm.googlemapsapi_2_demo;
  
  import android.app.Activity;
  import android.os.Bundle;
  
  
  public class SimpleMapActivity extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_simple_map);
      }
  }
  </code></pre>
  
  <p>The manifest file (with my MAPS API key removed.)</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="edu.utexas.scottm.googlemapsapi_2_demo" &gt;
  
      &lt;uses-feature
          android:glEsVersion="0x00020000"
          android:required="true"/&gt;
  
      &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;activity
              android:name=".SimpleMapActivity"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;meta-data
              android:name="com.google.android.gms.version"
              android:value="@integer/google_play_services_version" /&gt;
          &lt;meta-data
              android:name="com.google.android.maps.v2.MY_API_KEY"
              android:value="MY_API_KEY"/&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>The build.gradle file for the Module: app</p>
  
  <pre><code>apply plugin: 'com.android.application'
  
  android {
      compileSdkVersion 21
      buildToolsVersion "21.1.2"
  
      defaultConfig {
          applicationId "edu.utexas.scottm.googlemapsapi_2_demo"
          minSdkVersion 15
          targetSdkVersion 21
          versionCode 1
          versionName "1.0"
      }
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
      }
  }
  
  dependencies {
      compile 'com.android.support:appcompat-v7:21.0.3'
      compile 'com.google.android.gms:play-services:6.5.87'
      compile fileTree(dir: 'libs', include: ['*.jar'])
      compile 'com.android.support:appcompat-v7:21.0.3'
  }
  </code></pre>
  
  <p>I have created an Android Studio project from the Google Play Services sample apps found at \android-sdk\extras\google\google_play_services\samples\maps, and it works on the device, but this uses <code>FragmentActivity</code> and <code>SupportMapFragment</code>. </p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>Whole logcat in case needed:</p>
  
  <pre><code>02-12 19:59:49.496  23891-23891/edu.utexas.scottm.googlemapsapi_2_demo E/AndroidRuntime﹕ FATAL EXCEPTION: main
      java.lang.RuntimeException: Unable to start activity ComponentInfo{edu.utexas.scottm.googlemapsapi_2_demo/edu.utexas.scottm.googlemapsapi_2_demo.SimpleMapActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
              at android.app.ActivityThread.access$600(ActivityThread.java:141)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
              at android.os.Handler.dispatchMessage(Handler.java:99)
              at android.os.Looper.loop(Looper.java:137)
              at android.app.ActivityThread.main(ActivityThread.java:5039)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:511)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
              at dalvik.system.NativeStart.main(Native Method)
       Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
              at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
              at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
              at android.app.Activity.setContentView(Activity.java:1881)
              at edu.utexas.scottm.googlemapsapi_2_demo.SimpleMapActivity.onCreate(SimpleMapActivity.java:12)
              at android.app.Activity.performCreate(Activity.java:5104)
              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
              at android.app.ActivityThread.access$600(ActivityThread.java:141)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
              at android.os.Handler.dispatchMessage(Handler.java:99)
              at android.os.Looper.loop(Looper.java:137)
              at android.app.ActivityThread.main(ActivityThread.java:5039)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:511)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
              at dalvik.system.NativeStart.main(Native Method)
       Caused by: java.lang.RuntimeException: API key not found.  Check that &lt;meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="your API key"/&gt; is in the &lt;application&gt; element of AndroidManifest.xml
              at com.google.maps.api.android.lib6.gmm6.c.g.a(Unknown Source)
              at com.google.maps.api.android.lib6.c.i.a(Unknown Source)
              at com.google.maps.api.android.lib6.c.el.a(Unknown Source)
              at com.google.maps.api.android.lib6.c.ab.a(Unknown Source)
              at com.google.maps.api.android.lib6.c.aa.a(Unknown Source)
              at com.google.android.gms.maps.internal.x.onTransact(SourceFile:107)
              at android.os.Binder.transact(Binder.java:310)
              at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source)
              at com.google.android.gms.maps.MapFragment$a.onCreateView(Unknown Source)
              at com.google.android.gms.dynamic.a$4.b(Unknown Source)
              at com.google.android.gms.dynamic.a.a(Unknown Source)
              at com.google.android.gms.dynamic.a.onCreateView(Unknown Source)
              at com.google.android.gms.maps.MapFragment.onCreateView(Unknown Source)
              at android.app.Fragment.performCreateView(Fragment.java:1695)
              at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:861)
              at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
              at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1137)
              at android.app.Activity.onCreateView(Activity.java:4717)
              at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
              at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
              at android.app.Activity.setContentView(Activity.java:1881)
              at edu.utexas.scottm.googlemapsapi_2_demo.SimpleMapActivity.onCreate(SimpleMapActivity.java:12)
              at android.app.Activity.performCreate(Activity.java:5104)
              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
              at android.app.ActivityThread.access$600(ActivityThread.java:141)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
              at android.os.Handler.dispatchMessage(Handler.java:99)
              at android.os.Looper.loop(Looper.java:137)
              at android.app.ActivityThread.main(ActivityThread.java:5039)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:511)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
              at dalvik.system.NativeStart.main(Native Method)
  </code></pre>