Mapview in MapActivity Class not found
I've seen other threads here with similar symptoms, but none of the answers solved my problem. I'm following the Google map view tutorial, http://developer.android.com/resources/tutorials/views/hello-mapview.html and following all directions exactly, I keep getting this error .. java.lang.ClassNotFoundException: com.goodintechnology.maps.Mymap in loader dalvik.system.PathClassLoader[/data/app/com.goodintechnology.maps-1.apk]
I've started from scratch many times, but everytime开发者_Go百科, as soon as I change the Activity to MapActivity, the error is thrown. The app target is Google API 2.2, and the emulator is the same, with GPS enabled. I've tried putting the uses-library statement before, after, and in the Applications statement, but that didn't change anything. I even tried putting the statement vertically in the manifest. So, after about 8 hours messing with this, I put it to all of you. Here's the code:
AndroidManifest.xml
<uses-library android:name="com.google.android.maps" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Mymap"
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>
and the layout main.xml
<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="My key that was generated on google is here. trust me"
/>
</LinearLayout>
And the class Mymap
package com.goodintechnology.maps;
import com.google.android.maps.MapActivity;
import android.os.Bundle;
public class Mymap 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;
}
}
As mentioned this is all straight from Google Map View tutorial.
<uses-library android:name="com.google.android.maps" />
must be within <application> </application>
You said you tried that, but how you currently have it, it wont't work by any chance, so change that first.
Looks like maps.jar is not included in your project folder.
First of all put following line as child of application in your manifest file
<uses-library android:name="com.google.android.maps" />
After that right click on your project folder -> Properties -> Android -> In Project Build Target check whether checkbox has been selected for Google API only. if not check it. this will add maps.jar in your project and then your project will understand what is MapActivity.. :)
Did you download the Google API add-on for the SDK version you are using?
The Google APIs are not packaged with the standard SDK. You have to download them using the AVD Manager.
Edit - it says to add the <uses-library ... />
as a child of the <application>
tag.
This means to put it on the line after the <application>
tag but before </application>
.
I had the exact same issue until I created a new android virtual device.
Make sure that you create a virtual android device that also has the Google APIs in it also.. just having the APIs in the SDK and setting the run target to a version with Google APIs included isn't enough, you also need to make sure your emulator virtual device has the Google APIs from the Android SDK installed as well.
I have fixed that error installing eclipse in another location and installing Android plugins (ADT). That worked for me.
精彩评论