Я видел эту ветку
ClassNotFoundException Брошено с использованием MapView , но мне не помогло.
Код в моем манифесте файла:
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" />
<uses-library android:name="com.google.android.maps" >
</uses-library>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".GoogleMapsGpsActivity"
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>
и мой код для GoogleMapsGpsActivity.java :
public class GoogleMapsGpsActivity extends MapActivity {
private LocationManager lm;
private LocationListener locationListener;
private MapView mapView;
private MapController mc;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//---use the LocationManager class to obtain GPS locations---
lm = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
locationListener = new MyLocationListener();
lm.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
0,
0,
locationListener);
mapView = (MapView) findViewById(R.id.mapview);
mc = mapView.getController();
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
private class MyLocationListener implements LocationListener
{
@Override
public void onLocationChanged(Location loc) {
if (loc != null) {
Toast.makeText(getBaseContext(),
"Location changed : Lat: " + loc.getLatitude() +
" Lng: " + loc.getLongitude(),
5000).show();
GeoPoint p = new GeoPoint(
(int) (loc.getLatitude() * 1E6),
(int) (loc.getLongitude() * 1E6));
mc.animateTo(p);
mc.setZoom(16);
mapView.invalidate();
}
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status,
Bundle extras) {
// TODO Auto-generated method stub
}
}
}
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainlayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.googlemaps.gpsapp.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="key"
/>
</LinearLayout>
и я получаю ClassNotFoundException
, как видно из следующих выводов logcat
1-02 12:44:17.156: E/AndroidRuntime(1585): FATAL EXCEPTION: main
01-02 12:44:17.156: E/AndroidRuntime(1585): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.googlemaps.gpsapp/com.googlemaps.gpsapp.GoogleMapsGpsActivity}: java.lang.ClassNotFoundException: com.googlemaps.gpsapp.GoogleMapsGpsActivity in loader dalvik.system.PathClassLoader[/data/app/com.googlemaps.gpsapp-2.apk]
01-02 12:44:17.156: E/AndroidRuntime(1585): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
01-02 12:44:17.156: E/AndroidRuntime(1585): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
01-02 12:44:17.156: E/AndroidRuntime(1585): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-02 12:44:17.156: E/AndroidRuntime(1585): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
01-02 12:44:17.156: E/AndroidRuntime(1585): at android.os.Handler.dispatchMessage(Handler.java:99)
01-02 12:44:17.156: E/AndroidRuntime(1585): at android.os.Looper.loop(Looper.java:130)
01-02 12:44:17.156: E/AndroidRuntime(1585): at android.app.ActivityThread.main(ActivityThread.java:3683)
01-02 12:44:17.156: E/AndroidRuntime(1585): at java.lang.reflect.Method.invokeNative(Native Method)
01-02 12:44:17.156: E/AndroidRuntime(1585): at java.lang.reflect.Method.invoke(Method.java:507)
01-02 12:44:17.156: E/AndroidRuntime(1585): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-02 12:44:17.156: E/AndroidRuntime(1585): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-02 12:44:17.156: E/AndroidRuntime(1585): at dalvik.system.NativeStart.main(Native Method)
01-02 12:44:17.156: E/AndroidRuntime(1585): Caused by: java.lang.ClassNotFoundException: com.googlemaps.gpsapp.GoogleMapsGpsActivity in loader dalvik.system.PathClassLoader[/data/app/com.googlemaps.gpsapp-2.apk]
01-02 12:44:17.156: E/AndroidRuntime(1585): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
01-02 12:44:17.156: E/AndroidRuntime(1585): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
01-02 12:44:17.156: E/AndroidRuntime(1585): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
01-02 12:44:17.156: E/AndroidRuntime(1585): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
01-02 12:44:17.156: E/AndroidRuntime(1585): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
01-02 12:44:17.156: E/AndroidRuntime(1585): ... 11 more
Укажите мою ошибку
Редактировать
Спасибо всем за ответы, ошибка была в моем main.xml при объявлении вида карты
, она должна быть такой, как
<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="key"
/>
вместо того, что выложено выше.