Question

I am trying to get Google Maps Android API v2 working on Android 2.2 on a HTC Desire.

My main.xml contains the following:

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

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name="dk.sw510e13.user.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>
    </application>

</manifest>

This is my activity.

package dk.sw510e13.user;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;

public class MainActivity extends FragmentActivity {

    @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;
    }

}

When I run the application, I will get the following exception. It seems that it cannot find SupportMapFragment, however, I believe that I have both the support library and Google Play Services as dependencies. When creating the project in Android Studio I chose to add support for fragments.

01-17 23:52:55.237    2557-2557/dk.sw510e13.user E/AndroidRuntime﹕ FATAL EXCEPTION: main
        java.lang.RuntimeException: Unable to start activity ComponentInfo{dk.sw510e13.user/dk.sw510e13.user.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2787)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2803)
        at android.app.ActivityThread.access$2300(ActivityThread.java:135)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:144)
        at android.app.ActivityThread.main(ActivityThread.java:4937)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:521)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
        at dalvik.system.NativeStart.main(Native Method)
        Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:582)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
        at android.app.Activity.setContentView(Activity.java:1654)
        at dk.sw510e13.user.MainActivity.onCreate(MainActivity.java:13)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)
        ... 11 more
        Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
        at android.support.v4.app.Fragment.instantiate(Fragment.java:409)
        at android.support.v4.app.Fragment.instantiate(Fragment.java:377)
        at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:277)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:558)
        ... 20 more
        Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.SupportMapFragment in loader dalvik.system.PathClassLoader[/data/app/dk.sw510e13.user-2.apk]
        at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
        at android.support.v4.app.Fragment.instantiate(Fragment.java:399)
        ... 23 more

This is what I have in my dependencies.

Can anyone tell me what I am doing wrong?

UPDATE

This is my manifest.

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

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

    <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"/>
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name="dk.sw510e13.user.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="XXXXXX"/>
    </application>

</manifest>

Was it helpful?

Solution

This is the problem that seems to be occurred when missing Google Play services.

I request you to please follow the steps mentioned below to get the Google Play services to be included in your application.

copying the google-play-services.jar in libs folder and set in the build path of eclipse is a wrong method.

  1. import Google Play services in your project and add it in workspace. from location of your SDK folder.

\extras\google\google_play_services\libproject\google-play-services_lib

2! Now you added Google Play Services to your work space, we have to create a reference from our project to this library. Right-Click your project and choose “Properties” go to the Android section, in the lower part press the “Add…” button and add a reference to that library. Your result should be as in the screen shot bellow:

adding Google Play services library

enter image description here

Please Add

<permission
        android:name="com.anchit.locationapi.maps.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

in your manifest

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top