1

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();
    }
}
4

2 に答える 2

4

マニフェスト <uses-library android:name="com.google.android.maps" /> をに追加します<application> </application> Tag

これにより、クラスが見つからないという例外が解決されます。

于 2012-05-16T00:02:46.910 に答える
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>
于 2012-05-16T05:52:17.417 に答える