17

i am just following a simple map tutorial http://developer.android.com/resources/tutorials/views/hello-mapview.html but getting this error . I am new to android i tried to follow all the solution provided over the internet but no success yet. Please help me. My main .xml is below

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:apiKey="***"
/>

and manifestfile is this

Bobs
  • 21,870
  • 33
  • 134
  • 221
zeshu
  • 171
  • 1
  • 1
  • 3

9 Answers9

52

I had this problem and solved it by the following 2 steps:

1) Put the following line in the application (important) element of AndroidManifest.xml file.

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

2) extend MapActivity instead of Activity.

enjoy!

Bobs
  • 21,870
  • 33
  • 134
  • 221
12

Did you extend the main class as MapActivity?

public class a extends MapActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }
}
Lope Emano
  • 149
  • 1
  • 7
5

I had the same problem and about 3 hours of searching this is what I did to fix it, All in the manifest.

1) In my manifest this code was not in the right place

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

it should be here, under

    <application>

like this

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.example.package.name">
      ...
      <application android:name="MyApplication" >
        <uses-library android:name="com.google.android.maps" />
        ...
      </application>
      ...
    </manifest>

2) I lost a period somewhere in my manifest

    <activity 
        android:name="MyClass" //*****should be android:name=".MyClass"***
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MyClass />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

3) I didn't specify min sdk version which goes under

    <manifest> 

code:

    <uses-sdk android:minSdkVersion="7" />

4) to get the map to work through eclipse in debug mode follow these directions in your cmd or terminal http://www.buzztouch.com/resources/Obtaining_a_Google_Maps_API_Key_v1.0.pdf

I hope this helps someone

tricknology
  • 933
  • 1
  • 14
  • 26
3

I had the problem. Just extend MapActivity instead of Activity.

ManJan
  • 3,773
  • 3
  • 18
  • 22
1

I know the following wasn't the error of the original questioner - but since my problem led to the same error message, I thought I might as well add it in case someone in the future runs into it.

I checked all the other good hints, but none of them were missing in my project.

What finally solved the problem for me, was that I forgot to declar the MapView in the layout including the full package name. Neither Eclipse nor Lint did tell me about this:

<com.google.android.maps.MapView
    ...
    />
sunadorer
  • 3,700
  • 29
  • 40
1

The emulator on which you are running the application does not have google map jar. so create emulator from Google API run your application there.

See the image to create emulator with Google API

enter image description here

Sunil Kumar Sahoo
  • 49,865
  • 50
  • 172
  • 240
1

Insert this on your xml declaration of the MapView

xmlns:android="http://schemas.android.com/apk/res/android"
Jayson Tamayo
  • 2,311
  • 2
  • 37
  • 75
1

to work with google maps in addition to use the tag

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

in the tag, use another tag

<uses-permission android:name="android.permission.INTERNET"/>

inside the tag and you are done.

But remember you should run this application in the AVD compatible with Google Inc. API but not with Android API.

Another important thing is, be sure that you are using the MD5 API key instead of SHA1 or any other protocol API Key.

Chandra Sekhar
  • 16,511
  • 14
  • 71
  • 109
0

One gets this exception even if all the steps mentioned above are followed but api-key is not specified for the MapView. Just add the api-key which you got from google

<com.google.android.maps.MapView
        android:id="@+id/mapview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:clickable="true" 
         android:apiKey = "api-key_goes_here"
  >
Community
  • 1
  • 1
Jeevan
  • 7,674
  • 10
  • 45
  • 62