MapActivity中的ClassNotFoundException?

时间:2012-05-15 23:34:42

标签: android exception android-mapview classnotfoundexception

当我创建MapActivity时 我收到了这个错误

05-15 23:31:37.231: E/AndroidRuntime(760): FATAL EXCEPTION: main
05-15 23:31:37.231: E/AndroidRuntime(760): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{pit.opensource.mapapp/pit.opensource.mapapp.M1MapAppActivity}: java.lang.ClassNotFoundException: pit.opensource.mapapp.M1MapAppActivity in loader dalvik.system.PathClassLoader[/data/app/pit.opensource.mapapp-2.apk]
05-15 23:31:37.231: E/AndroidRuntime(760):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
05-15 23:31:37.231: E/AndroidRuntime(760):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
05-15 23:31:37.231: E/AndroidRuntime(760):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-15 23:31:37.231: E/AndroidRuntime(760):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
05-15 23:31:37.231: E/AndroidRuntime(760):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-15 23:31:37.231: E/AndroidRuntime(760):  at android.os.Looper.loop(Looper.java:130)
05-15 23:31:37.231: E/AndroidRuntime(760):  at android.app.ActivityThread.main(ActivityThread.java:3683)
05-15 23:31:37.231: E/AndroidRuntime(760):  at java.lang.reflect.Method.invokeNative(Native Method)
05-15 23:31:37.231: E/AndroidRuntime(760):  at java.lang.reflect.Method.invoke(Method.java:507)
05-15 23:31:37.231: E/AndroidRuntime(760):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-15 23:31:37.231: E/AndroidRuntime(760):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-15 23:31:37.231: E/AndroidRuntime(760):  at dalvik.system.NativeStart.main(Native Method)
05-15 23:31:37.231: E/AndroidRuntime(760): Caused by: java.lang.ClassNotFoundException: pit.opensource.mapapp.M1MapAppActivity in loader dalvik.system.PathClassLoader[/data/app/pit.opensource.mapapp-2.apk]
05-15 23:31:37.231: E/AndroidRuntime(760):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
05-15 23:31:37.231: E/AndroidRuntime(760):  at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
05-15 23:31:37.231: E/AndroidRuntime(760):  at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
05-15 23:31:37.231: E/AndroidRuntime(760):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
05-15 23:31:37.231: E/AndroidRuntime(760):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)

AndroidManifest.xml文件是:

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

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

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".M1MapAppActivity"
            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>

</manifest>

问题是什么?

更新

MapActivity类的代码:

package pit.opensource.mapapp;


import android.content.Context;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;
import com.google.android.maps.OverlayItem;

public class M1MapAppActivity extends MapActivity {

    private MapController mapController;
    private MapView mapView;
    private LocationManager locationManager;
    private MyOverlays itemizedoverlay;
    private MyLocationOverlay myLocationOverlay;

    @Override
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.main); // bind the layout to the activity

        // Configure the Map
        mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);
        mapView.setSatellite(true);
        mapController = mapView.getController();
        mapController.setZoom(14); // Zoon 1 is world view
        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
                0, new GeoUpdateHandler());

        myLocationOverlay = new MyLocationOverlay(this, mapView);
        mapView.getOverlays().add(myLocationOverlay);

        myLocationOverlay.runOnFirstFix(new Runnable() {
            public void run() {
                mapView.getController().animateTo(
                        myLocationOverlay.getMyLocation());
            }
        });

        Drawable drawable = this.getResources().getDrawable(R.drawable.point);
        itemizedoverlay = new MyOverlays(this, drawable);
        createMarker();
    }

    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }

    public class GeoUpdateHandler implements LocationListener {

        @Override
        public void onLocationChanged(Location location) {
            int lat = (int) (location.getLatitude() * 1E6);
            int lng = (int) (location.getLongitude() * 1E6);
            GeoPoint point = new GeoPoint(lat, lng);
            createMarker();
            mapController.animateTo(point); // mapController.setCenter(point);

        }

        @Override
        public void onProviderDisabled(String provider) {
        }

        @Override
        public void onProviderEnabled(String provider) {
        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
        }
    }

    private void createMarker() {
        GeoPoint p = mapView.getMapCenter();
        OverlayItem overlayitem = new OverlayItem(p, "", "");
        itemizedoverlay.addOverlay(overlayitem);
        if (itemizedoverlay.size() > 0) {
            mapView.getOverlays().add(itemizedoverlay);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        myLocationOverlay.enableMyLocation();
        myLocationOverlay.enableCompass();
    }

    @Override
    protected void onPause() {
        super.onResume();
        myLocationOverlay.disableMyLocation();
        myLocationOverlay.disableCompass();
    }
}

2 个答案:

答案 0 :(得分:4)

添加您的清单  <uses-library android:name="com.google.android.maps" /><application> </application> Tag

这将解决你的班级未找到的异常。

答案 1 :(得分:1)

如果您的项目包含多个包,请尝试在您的Android清单文件中插入包名称;

  <activity
        android:name="com.PackageName.M1MapAppActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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