Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to implement a map using map api v2. I searched here for answer to my problem, but did not find the right answer that helps me out. Any help is appreciated. Thank you.

My xml code:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      tools:context=".SupportMapFragmentActivity" >

<fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment" />

</RelativeLayout>

My Manifest:

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

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

<permission
    android:name="com.truiton.supportmapfragment.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true"/>

<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-library android:name="com.google.android.maps" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.googlemap.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="My API Key"/>

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

</application>

</manifest>

And the Main: package com.example.googlemap;

import com.google.android.gms.internal.fm;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.SupportMapFragment;

import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.view.Menu;

public class MainActivity extends FragmentActivity {

@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    GoogleMap map;
    FragmentManager fmanager = getSupportFragmentManager();
    Fragment fragment = fmanager.findFragmentById(R.id.map);
    SupportMapFragment supportmapfragment = (SupportMapFragment)fragment;
    map = supportmapfragment.getMap();

}

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

}

And then i got those Errors:

02-16 17:09:39.014: E/AndroidRuntime(13283): FATAL EXCEPTION: main
02-16 17:09:39.014: E/AndroidRuntime(13283): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.googlemap/com.example.googlemap.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
02-16 17:09:39.014: E/AndroidRuntime(13283):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2071)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2096)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at android.app.ActivityThread.access$600(ActivityThread.java:138)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at android.os.Handler.dispatchMessage(Handler.java:99)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at android.os.Looper.loop(Looper.java:213)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at android.app.ActivityThread.main(ActivityThread.java:4787)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at java.lang.reflect.Method.invokeNative(Native Method)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at java.lang.reflect.Method.invoke(Method.java:511)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at dalvik.system.NativeStart.main(Native Method)
02-16 17:09:39.014: E/AndroidRuntime(13283): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
02-16 17:09:39.014: E/AndroidRuntime(13283):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:262)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at android.app.Activity.setContentView(Activity.java:1867)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at com.example.googlemap.MainActivity.onCreate(MainActivity.java:12)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at android.app.Activity.performCreate(Activity.java:5008)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2035)
02-16 17:09:39.014: E/AndroidRuntime(13283):    ... 11 more
02-16 17:09:39.014: E/AndroidRuntime(13283): Caused by: java.lang.RuntimeException: API key not found.  Check that <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml
02-16 17:09:39.014: E/AndroidRuntime(13283):    at maps.e.ay.a(Unknown Source)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at maps.e.ay.a(Unknown Source)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at maps.e.ay.a(Unknown Source)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at maps.e.ay.a(Unknown Source)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at maps.e.al.a(Unknown Source)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at maps.e.bg.a(Unknown Source)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at maps.e.bf.a(Unknown Source)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at eio.onTransact(SourceFile:107)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at android.os.Binder.transact(Binder.java:326)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at com.google.android.gms.maps.MapFragment$a.onCreateView(Unknown Source)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at com.google.android.gms.dynamic.a$4.b(Unknown Source)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at com.google.android.gms.dynamic.a.a(Unknown Source)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at com.google.android.gms.dynamic.a.onCreateView(Unknown Source)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at com.google.android.gms.maps.MapFragment.onCreateView(Unknown Source)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:811)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1017)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1116)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at android.app.Activity.onCreateView(Activity.java:4664)
02-16 17:09:39.014: E/AndroidRuntime(13283):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
02-16 17:09:39.014: E/AndroidRuntime(13283):    ... 20 more

I be glad if you can help me!

share|improve this question
1  
do you have the real api key in place of android:value="My API Key"/>? –  Raghunandan Feb 16 at 16:26
    
Also, get rid of <uses-library>, as that is not used for Maps V2. –  CommonsWare Feb 16 at 16:59
    
@Raghunandan: Yes, i have there the real Key. –  Chadirra Feb 16 at 18:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.