2

I'm working on the tutorial for Google Maps Android API v2 at : https://developers.google.com/maps/documentation/android/start

I'm only trying to get a simple map shown in my app, yet it's not working (the app doesn't open, and there's a message box with "The "Test2" application has stopped.") and I don't know why. I followed exactly what was said in the tutorial.

Here's my code :

AndroidManifest.xml :

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

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

    <permission
        android:name="com.example.test2.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"/>

    <uses-permission android:name="com.example.test2.permission.MAPS_RECEIVE"/>
    <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"/>

    <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"
        android:theme="@style/AppTheme" >

        <activity
            android:name="com.example.test2.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="The key"/>
    </application>

</manifest>

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

MainActivity.java :

package com.example.test2;

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.activity_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;
    }
}

Thank you in advance.

EDIT :

Here's the logcat :

04-09 11:58:31.689: E/AndroidRuntime(4028): FATAL EXCEPTION: main
04-09 11:58:31.689: E/AndroidRuntime(4028): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.test2/com.example.test2.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class fragment
04-09 11:58:31.689: E/AndroidRuntime(4028):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
04-09 11:58:31.689: E/AndroidRuntime(4028):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
04-09 11:58:31.689: E/AndroidRuntime(4028):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
04-09 11:58:31.689: E/AndroidRuntime(4028):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
04-09 11:58:31.689: E/AndroidRuntime(4028):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-09 11:58:31.689: E/AndroidRuntime(4028):     at android.os.Looper.loop(Looper.java:137)
04-09 11:58:31.689: E/AndroidRuntime(4028):     at android.app.ActivityThread.main(ActivityThread.java:4745)
04-09 11:58:31.689: E/AndroidRuntime(4028):     at java.lang.reflect.Method.invokeNative(Native Method)
04-09 11:58:31.689: E/AndroidRuntime(4028):     at java.lang.reflect.Method.invoke(Method.java:511)
04-09 11:58:31.689: E/AndroidRuntime(4028):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
04-09 11:58:31.689: E/AndroidRuntime(4028):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
04-09 11:58:31.689: E/AndroidRuntime(4028):     at dalvik.system.NativeStart.main(Native Method)
04-09 11:58:31.689: E/AndroidRuntime(4028): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class fragment
04-09 11:58:31.689: E/AndroidRuntime(4028):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
04-09 11:58:31.689: E/AndroidRuntime(4028):     at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
04-09 11:58:31.689: E/AndroidRuntime(4028):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
04-09 11:58:31.689: E/AndroidRuntime(4028):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
04-09 11:58:31.689: E/AndroidRuntime(4028):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
04-09 11:58:31.689: E/AndroidRuntime(4028):     at android.app.Activity.setContentView(Activity.java:1867)
04-09 11:58:31.689: E/AndroidRuntime(4028):     at com.example.test2.MainActivity.onCreate(MainActivity.java:12)
04-09 11:58:31.689: E/AndroidRuntime(4028):     at android.app.Activity.performCreate(Activity.java:5008)
04-09 11:58:31.689: E/AndroidRuntime(4028):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
04-09 11:58:31.689: E/AndroidRuntime(4028):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
04-09 11:58:31.689: E/AndroidRuntime(4028):     ... 11 more
04-09 11:58:31.689: E/AndroidRuntime(4028): Caused by: android.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
04-09 11:58:31.689: E/AndroidRuntime(4028):     at android.app.Fragment.instantiate(Fragment.java:584)
04-09 11:58:31.689: E/AndroidRuntime(4028):     at android.app.Fragment.instantiate(Fragment.java:552)
04-09 11:58:31.689: E/AndroidRuntime(4028):     at android.app.Activity.onCreateView(Activity.java:4656)
04-09 11:58:31.689: E/AndroidRuntime(4028):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
04-09 11:58:31.689: E/AndroidRuntime(4028):     ... 20 more
04-09 11:58:31.689: E/AndroidRuntime(4028): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.SupportMapFragment
04-09 11:58:31.689: E/AndroidRuntime(4028):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
04-09 11:58:31.689: E/AndroidRuntime(4028):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
04-09 11:58:31.689: E/AndroidRuntime(4028):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
04-09 11:58:31.689: E/AndroidRuntime(4028):     at android.app.Fragment.instantiate(Fragment.java:574)
04-09 11:58:31.689: E/AndroidRuntime(4028):     ... 23 more
3
  • 2
    post your logcat errors. Apr 9, 2013 at 9:06
  • In which device you are trying to run. This will work only in api level 16 and 17 according to your manifest and also in emulator..
    – Jai Kumar
    Apr 9, 2013 at 9:08
  • 2
    I removed your API key from the post, next time don't paste it for your own privacy.
    – Emil Adz
    Apr 9, 2013 at 9:09

2 Answers 2

6

The only problem I currently see here is this line:

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

This line belong to Google Map API v1 and shouldn't be written in Google Map API V2.

We can't help you more then this without the logcat output.

UPDATE:

If now you pasted the right manifest file then your current problem is:

1. You are developing you application for min SDK 8 so you have to use the SupportMapFragment instead of the MapFragment object in you XML layout file of the Activity. like this:

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

You can take a look at this blog post I wrote on how to add Google Map API V2 to you application:

Google Map API V2

4
  • Sorry, my mistake, I copypasted a wrong version of the code. The version I have right now doesn't have this line, and the api levels are the right ones, yet it stil doesn't work.
    – Apoz
    Apr 9, 2013 at 9:23
  • it look like you have a problem with the referencing of google-play-services library. please check the first 3 steps of the guide I posted in the answer.
    – Emil Adz
    Apr 9, 2013 at 10:39
  • OK, it seems it was the problem, but I wasn't referencing the google-play-services library correctly, but now I have another problem. I'm going to post it in another question.
    – Apoz
    Apr 9, 2013 at 12:31
  • Great, you can post a link here as soon as you post a new question if you need my assistance.
    – Emil Adz
    Apr 9, 2013 at 12:37
0

You forget the mention updated google-play-service lib version in AndroidMenifest.xml

 <application
        android:name="packagename"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

  </application>

Not the answer you're looking for? Browse other questions tagged or ask your own question.