1

I'm trying to do the example here https://developers.google.com/maps/documentation/android/start

I'm working in Eclipse and there are no errors displayed in the code. I have linked the google-play-services-lib and set the project build target as the most recent version of the Google API. I've entered my API key and have turned on the google maps android api v2 in the services menu in the console. Any ideas why I'm getting this error? I'm testing on a real device, a nexus 5 running lollipop (5.0.1)

My logcat is below

FATAL EXCEPTION: main
02-23 17:47:48.927: E/AndroidRuntime(8735): Process: com.juliette.basicgooglemap, PID: 8735
02-23 17:47:48.927: E/AndroidRuntime(8735): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.juliette.basicgooglemap/com.juliette.basicgooglemap.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
02-23 17:47:48.927: E/AndroidRuntime(8735):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
02-23 17:47:48.927: E/AndroidRuntime(8735):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
02-23 17:47:48.927: E/AndroidRuntime(8735):     at android.app.ActivityThread.access$800(ActivityThread.java:144)
02-23 17:47:48.927: E/AndroidRuntime(8735):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
02-23 17:47:48.927: E/AndroidRuntime(8735):     at android.os.Handler.dispatchMessage(Handler.java:102)
02-23 17:47:48.927: E/AndroidRuntime(8735):     at android.os.Looper.loop(Looper.java:135)
02-23 17:47:48.927: E/AndroidRuntime(8735):     at android.app.ActivityThread.main(ActivityThread.java:5221)
02-23 17:47:48.927: E/AndroidRuntime(8735):     at java.lang.reflect.Method.invoke(Native Method)
02-23 17:47:48.927: E/AndroidRuntime(8735):     at java.lang.reflect.Method.invoke(Method.java:372)
02-23 17:47:48.927: E/AndroidRuntime(8735):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
02-23 17:47:48.927: E/AndroidRuntime(8735):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
02-23 17:47:48.927: E/AndroidRuntime(8735): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
02-23 17:47:48.927: E/AndroidRuntime(8735):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
02-23 17:47:48.927: E/AndroidRuntime(8735):     at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
02-23 17:47:48.927: E/AndroidRuntime(8735):     at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
02-23 17:47:48.927: E/AndroidRuntime(8735):     at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
02-23 17:47:48.927: E/AndroidRuntime(8735):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:377)
02-23 17:47:48.927: E/AndroidRuntime(8735):     at android.app.Activity.setContentView(Activity.java:2144)
02-23 17:47:48.927: E/AndroidRuntime(8735):     at com.juliette.basicgooglemap.MainActivity.onCreate(MainActivity.java:11)
02-23 17:47:48.927: E/AndroidRuntime(8735):     at android.app.Activity.performCreate(Activity.java:5933)
02-23 17:47:48.927: E/AndroidRuntime(8735):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
02-23 17:47:48.927: E/AndroidRuntime(8735):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
02-23 17:47:48.927: E/AndroidRuntime(8735):     ... 10 more
02-23 17:47:48.927: E/AndroidRuntime(8735): 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
02-23 17:47:48.927: E/AndroidRuntime(8735):     at android.app.Fragment.instantiate(Fragment.java:618)
02-23 17:47:48.927: E/AndroidRuntime(8735):     at android.app.Fragment.instantiate(Fragment.java:582)
02-23 17:47:48.927: E/AndroidRuntime(8735):     at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2108)
02-23 17:47:48.927: E/AndroidRuntime(8735):     at android.app.Activity.onCreateView(Activity.java:5282)
02-23 17:47:48.927: E/AndroidRuntime(8735):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
02-23 17:47:48.927: E/AndroidRuntime(8735):     ... 19 more
02-23 17:47:48.927: E/AndroidRuntime(8735): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.MapFragment" on path: DexPathList[[zip file "/data/app/com.juliette.basicgooglemap-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
02-23 17:47:48.927: E/AndroidRuntime(8735):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
02-23 17:47:48.927: E/AndroidRuntime(8735):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
02-23 17:47:48.927: E/AndroidRuntime(8735):     at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
02-23 17:47:48.927: E/AndroidRuntime(8735):     at android.app.Fragment.instantiate(Fragment.java:604)
02-23 17:47:48.927: E/AndroidRuntime(8735):     ... 23 more
02-23 17:47:48.927: E/AndroidRuntime(8735):     Suppressed: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment
02-23 17:47:48.927: E/AndroidRuntime(8735):         at java.lang.Class.classForName(Native Method)
02-23 17:47:48.927: E/AndroidRuntime(8735):         at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
02-23 17:47:48.927: E/AndroidRuntime(8735):         at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
02-23 17:47:48.927: E/AndroidRuntime(8735):         at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
02-23 17:47:48.927: E/AndroidRuntime(8735):         ... 25 more
02-23 17:47:48.927: E/AndroidRuntime(8735):     Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

Here's the manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.juliette.basicgooglemap"
android:versionCode="1"
android:versionName="1.0" >

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

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

<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.gms.version"
        android:value="@integer/google_play_services_version" />
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="API_KEY"/>

<uses-library android:name="com.google.android.maps" />
</application>

</manifest>

Here's my main activity

package com.juliette.basicgooglemap;

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.activity_main);
    }
}

and the layout

<?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.SupportMapFragment"/>

Any suggestions are greatly appreciated, I'm very confused.

Joolz Zenda
  • 47
  • 1
  • 6
  • In the manifest did you replace `API_KEY` with the real key ?. Ensure you imported the library correctly your error seems to be due to missing library. Use this guide http://developer.android.com/google/play-services/setup.html – Psypher Feb 23 '15 at 18:31
  • @Ranjith I have used the real key in the code and I just double checked my process against the link you gave and I still have the same error – Joolz Zenda Feb 23 '15 at 18:46

1 Answers1

2
  1. It might have caused because the library was not imported correctly, follow the steps in this link

  2. If that didn't resolve and you have set up the library correctly, this may be because proguard might have stripped away play services. To avoid it add the following in proguard-project.txt

-keep class * extends java.util.ListResourceBundle {
    protected Object[][] getContents();
}

-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    public static final *** NULL;
}

-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
    @com.google.android.gms.common.annotation.KeepName *;
}  
-keepnames class * implements android.os.Parcelable {
    public static final ** CREATOR;
}
  1. Your suggested Android manifest fixes

You might not have added the key, I see 'API_KEY' string instead of the key, it should be something like this(obviously the key will be different)

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

You are missing these in the AndroidManifest.xml,

<permission
    android:name="com.juliette.basicgooglemap.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />
<uses-permission android:name="com.juliette.basicgooglemap.permission.MAPS_RECEIVE" />

Add this too:

<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>

Next setup your layout and code like this post, you are not using the fragment properly.

Community
  • 1
  • 1
Psypher
  • 10,717
  • 12
  • 59
  • 83
  • I've tried all three suggestions, still the same issue. I have also added to the manifest but still no luck. Any other suggestions? – Joolz Zenda Feb 23 '15 at 19:27
  • @JoolzZenda Just updated the post, try adding the new permission added and setup the layout,java code as mentioned in the post – Psypher Feb 23 '15 at 19:41
  • It's working now, it was the fragment activity like you suggested. Thank you so much for your help :) – Joolz Zenda Feb 23 '15 at 20:08