0

I'm using this tutorial from Google for MapsActivity but for some reason I have not been getting the required output, the application crashes.

Here is the code I'm using:

  1. Manifest.xml

    <uses-sdk
        android:minSdkVersion="15"
        android:targetSdkVersion="15" />
    
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.ajinkya.samplemapsdemo.permission.MAPS_RECEIVE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    
    <permission
        android:name="com.ajinkya.samplemapsdemo.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />
    
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />
    
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.ajinkya.samplemapsdemo.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="blahblahblahkey" />
    </application>
    

  2. main.xml

    <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"/>
    

  3. MainActivity.java

     package com.ajinkya.samplemapsdemo;
     import android.os.Bundle;
     import android.app.Activity;
     import android.view.Menu;
    
     public class MainActivity extends Activity {
    
    
     @Override
      protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
      }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }}
    

According to Google, a map should be displayed, which is not happening. It gives me the message:

Unfortunately, samplemapsdemo has stopped.

Here is the log:

08-01 18:30:21.671: D/ActivityThread(10657): setTargetHeapUtilization:0.25
08-01 18:30:21.671: D/ActivityThread(10657): setTargetHeapIdealFree:8388608
08-01 18:30:21.671: D/ActivityThread(10657): setTargetHeapConcurrentStart:2097152
08-01 18:30:21.741: W/dalvikvm(10657): threadid=1: thread exiting with uncaught exception (group=0x40a9f390)
08-01 18:31:36.581: D/ActivityThread(10705): setTargetHeapUtilization:0.25
08-01 18:31:36.581: D/ActivityThread(10705): setTargetHeapIdealFree:8388608
08-01 18:31:36.591: D/ActivityThread(10705): setTargetHeapConcurrentStart:2097152
08-01 18:31:36.801: W/dalvikvm(10705): threadid=1: thread exiting with uncaught exception (group=0x40a9f390)
08-01 18:31:36.831: E/AndroidRuntime(10705): FATAL EXCEPTION: main
08-01 18:31:36.831: E/AndroidRuntime(10705): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ajinkya.samplemapsdemo/com.ajinkya.samplemapsdemo.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1959)
08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1984)
08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.app.ActivityThread.access$600(ActivityThread.java:126)
08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1150)
08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.os.Looper.loop(Looper.java:137)
08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.app.ActivityThread.main(ActivityThread.java:4456)
08-01 18:31:36.831: E/AndroidRuntime(10705):    at java.lang.reflect.Method.invokeNative(Native Method)
08-01 18:31:36.831: E/AndroidRuntime(10705):    at java.lang.reflect.Method.invoke(Method.java:511)
08-01 18:31:36.831: E/AndroidRuntime(10705):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
08-01 18:31:36.831: E/AndroidRuntime(10705):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
08-01 18:31:36.831: E/AndroidRuntime(10705):    at dalvik.system.NativeStart.main(Native Method)
08-01 18:31:36.831: E/AndroidRuntime(10705): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
08-01 18:31:36.831: E/AndroidRuntime(10705):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.app.Activity.setContentView(Activity.java:1835)
08-01 18:31:36.831: E/AndroidRuntime(10705):    at com.ajinkya.samplemapsdemo.MainActivity.onCreate(MainActivity.java:15)
08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.app.Activity.performCreate(Activity.java:4465)
08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1923)
08-01 18:31:36.831: E/AndroidRuntime(10705):    ... 11 more
08-01 18:31:36.831: E/AndroidRuntime(10705): 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
08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.app.Fragment.instantiate(Fragment.java:581)
08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.app.Fragment.instantiate(Fragment.java:549)
08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.app.Activity.onCreateView(Activity.java:4235)
08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:673)
08-01 18:31:36.831: E/AndroidRuntime(10705):    ... 21 more
08-01 18:31:36.831: E/AndroidRuntime(10705): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment
08-01 18:31:36.831: E/AndroidRuntime(10705):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
08-01 18:31:36.831: E/AndroidRuntime(10705):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
08-01 18:31:36.831: E/AndroidRuntime(10705):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.app.Fragment.instantiate(Fragment.java:571)
08-01 18:31:36.831: E/AndroidRuntime(10705):    ... 24 more

I believe that this line may be the root cause of all of the problems:

08-01 18:31:36.831: E/AndroidRuntime(10705): 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

Any help would be appreciated.

Flyk
  • 245
  • 2
  • 8
  • 19
Ajinkya
  • 147
  • 1
  • 2
  • 11
  • have you referenced the google pla services library project. also have you enabled maps for android in google api console? – Raghunandan Aug 01 '13 at 13:24
  • i(Shift not working) obtained the key via google api console, so that key is enabled, but the thing is :::: How to reference the google play services library project ? Because i (Shift not working :D ) have installed the google play services through Android SDK – Ajinkya Aug 01 '13 at 14:19
  • http://stackoverflow.com/questions/17611017/importing-google-play-service-library-showing-a-red-x-next-to-this-reference-and/17611095#17611095. fist reference the library project as suggestd in the link then goto the google api console and enable maps for android as suggested in the docs – Raghunandan Aug 01 '13 at 14:23
  • did the referencing part, and enabled maps for android v2 via google api console, but get an "Android library projects cannot be launched" error when try to run the application – Ajinkya Aug 01 '13 at 14:50
  • why are you launching library project you should launch your androi map project. library project is only for referencing – Raghunandan Aug 01 '13 at 14:51
  • after adding the library as you said, I launched the main project , but got that error :X – Ajinkya Aug 01 '13 at 15:39
  • looks like its a broken link redo the steps and make sure you do it right. if you do it right i don't see any reason why it won't work. Also this is leading to a discussion. if you have further doubts as a new question – Raghunandan Aug 01 '13 at 16:21

0 Answers0