title: Unable instantiate android.gms.maps.MapFragment
body: <p>I try to do a demo with google maps android v2 with very simple activity, just copy code from google page:
  <a href="https://developers.google.com/maps/documentation/android/start#adding_the_api_key_to_your_application" rel="nofollow noreferrer">https://developers.google.com/maps/documentation/android/start#adding_the_api_key_to_your_application</a></p>
  
  <p>for activity:</p>
  
  <pre><code>package com.example.mapdemo;
  
  import android.app.Activity;
  import android.os.Bundle;
  
  public class MainActivity extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
      }
  }
  </code></pre>
  
  <p>for layout:</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"
    class="com.google.android.gms.maps.MapFragment"/&gt;
  </code></pre>
  
  <p>I had apply for a api key according to page and modify my androidmanifest.xml file, just like this:</p>
  
  <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.wenhai.driverschool"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk
          android:minSdkVersion="8"
          android:targetSdkVersion="15" /&gt;
  
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  
      &lt;!-- add for map2 --&gt;
      &lt;permission
          android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
          android:protectionLevel="signature" /&gt;
  
      &lt;uses-permission android:name="com.example.mapdemo.permission.MAPS_RECEIVE" /&gt;
      &lt;uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /&gt;
      &lt;!-- External storage for caching. --&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  
      &lt;!-- Maps API needs OpenGL ES 2.0. --&gt;
      &lt;uses-feature
          android:glEsVersion="0x00020000"
          android:required="true" /&gt;
  
      &lt;application
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;meta-data
              android:name="com.google.android.maps.v2.API_KEY"
              android:value="AIzaSyDVAF4WaVSVRDKJx87It8OSFP5txQcPabc" /&gt;
  
          &lt;activity
              android:name=".MainActivity"
              android:label="@string/title_activity_main" &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;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>I also reference my app to google-play-services_lib in eclipse.</p>
  
  <p>but everytime, error report in logcat like this:</p>
  
  <pre><code>2-05 16:22:53.609: E/AndroidRuntime(21623): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.wenhai.driverschool/com.wenhai.driverschool.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
  12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
  12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
  12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.app.ActivityThread.access$600(ActivityThread.java:127)
  12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
  12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.os.Handler.dispatchMessage(Handler.java:99)
  12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.os.Looper.loop(Looper.java:137)
  12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.app.ActivityThread.main(ActivityThread.java:4441)
  12-05 16:22:53.609: E/AndroidRuntime(21623):    at java.lang.reflect.Method.invokeNative(Native Method)
  12-05 16:22:53.609: E/AndroidRuntime(21623):    at java.lang.reflect.Method.invoke(Method.java:511)
  12-05 16:22:53.609: E/AndroidRuntime(21623):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
  12-05 16:22:53.609: E/AndroidRuntime(21623):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
  12-05 16:22:53.609: E/AndroidRuntime(21623):    at dalvik.system.NativeStart.main(Native Method)
  12-05 16:22:53.609: E/AndroidRuntime(21623): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
  12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
  12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
  12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
  12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
  12-05 16:22:53.609: E/AndroidRuntime(21623):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:255)
  12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.app.Activity.setContentView(Activity.java:1835)
  12-05 16:22:53.609: E/AndroidRuntime(21623):    at com.wenhai.driverschool.MainActivity.onCreate(MainActivity.java:11)
  12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.app.Activity.performCreate(Activity.java:4465)
  12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
  12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
  12-05 16:22:53.609: E/AndroidRuntime(21623):    ... 11 more
  12-05 16:22:53.609: E/AndroidRuntime(21623): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.MapFragment: make sure class name exists, is public, and has an empty constructor that is public
  12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.app.Fragment.instantiate(Fragment.java:581)
  12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.app.Fragment.instantiate(Fragment.java:549)
  12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.app.Activity.onCreateView(Activity.java:4235)
  12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:673)
  12-05 16:22:53.609: E/AndroidRuntime(21623):    ... 20 more
  12-05 16:22:53.609: E/AndroidRuntime(21623): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment
  12-05 16:22:53.609: E/AndroidRuntime(21623):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
  12-05 16:22:53.609: E/AndroidRuntime(21623):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
  12-05 16:22:53.609: E/AndroidRuntime(21623):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
  12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.app.Fragment.instantiate(Fragment.java:571)
  12-05 16:22:53.609: E/AndroidRuntime(21623):    ... 23 more
  </code></pre>
  
  <p>I don't know the reason for this.</p>
  
  <p>If i add google-play-services.jar into my project, it will report another error:</p>
  
  <pre><code>12-05 16:34:23.269: E/AndroidRuntime(22638): FATAL EXCEPTION: main
  12-05 16:34:23.269: E/AndroidRuntime(22638): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
  12-05 16:34:23.269: E/AndroidRuntime(22638):    at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
  12-05 16:34:23.269: E/AndroidRuntime(22638):    at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
  12-05 16:34:23.269: E/AndroidRuntime(22638):    at android.app.Activity.onCreateView(Activity.java:4242)
  12-05 16:34:23.269: E/AndroidRuntime(22638):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:673)
  12-05 16:34:23.269: E/AndroidRuntime(22638):    at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
  12-05 16:34:23.269: E/AndroidRuntime(22638):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
  12-05 16:34:23.269: E/AndroidRuntime(22638):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
  12-05 16:34:23.269: E/AndroidRuntime(22638):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:255)
  12-05 16:34:23.269: E/AndroidRuntime(22638):    at android.app.Activity.setContentView(Activity.java:1835)
  12-05 16:34:23.269: E/AndroidRuntime(22638):    at com.wenhai.driverschool.MainActivity.onCreate(MainActivity.java:11)
  12-05 16:34:23.269: E/AndroidRuntime(22638):    at android.app.Activity.performCreate(Activity.java:4465)
  12-05 16:34:23.269: E/AndroidRuntime(22638):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
  12-05 16:34:23.269: E/AndroidRuntime(22638):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
  12-05 16:34:23.269: E/AndroidRuntime(22638):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
  12-05 16:34:23.269: E/AndroidRuntime(22638):    at android.app.ActivityThread.access$600(ActivityThread.java:127)
  12-05 16:34:23.269: E/AndroidRuntime(22638):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
  12-05 16:34:23.269: E/AndroidRuntime(22638):    at android.os.Handler.dispatchMessage(Handler.java:99)
  12-05 16:34:23.269: E/AndroidRuntime(22638):    at android.os.Looper.loop(Looper.java:137)
  12-05 16:34:23.269: E/AndroidRuntime(22638):    at android.app.ActivityThread.main(ActivityThread.java:4441)
  12-05 16:34:23.269: E/AndroidRuntime(22638):    at java.lang.reflect.Method.invokeNative(Native Method)
  12-05 16:34:23.269: E/AndroidRuntime(22638):    at java.lang.reflect.Method.invoke(Method.java:511)
  12-05 16:34:23.269: E/AndroidRuntime(22638):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
  12-05 16:34:23.269: E/AndroidRuntime(22638):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
  12-05 16:34:23.269: E/AndroidRuntime(22638):    at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Anyone can help me about this?</p>