0

我知道这可能会变成一个非常愚蠢的问题,所以请不要仅仅看标题就让我失望。一旦我尝试使用我的 Android 应用程序启动 MapActivity 扩展类,最奇怪的事情就会发生在我身上。

我知道这方面有很多问题,我做了我的研究,但他们中的大多数都专注于检查名称是否对应,没有一个对我有用。

即使我更新了我的清单,类在那里我得到一个 ClassNotFound 异常......

请让我知道我做错了什么。

安卓清单:

<activity
        android:name="ro.gebs.captoom.activities.LocationActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

位置活动类:

package ro.gebs.captoom.activities;

import android.os.Bundle;

import com.example.captoom.R;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;

public class LocationActivity extends MapActivity {

    MapView mapView = null;
    MyLocationOverlay myLocationOverlay = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // main.xml contains a MapView
        setContentView(R.layout.preview_location);

        // extract MapView from layout
        mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);

        // create an overlay that shows our current location
        myLocationOverlay = new MyLocationOverlay(this, mapView);

        // add this overlay to the MapView and refresh it
        mapView.getOverlays().add(myLocationOverlay);
        mapView.postInvalidate();
    }

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

    @Override
    protected void onResume() {
        super.onResume();
        // when our activity resumes, we want to register for location updates
        myLocationOverlay.enableMyLocation();
    }

    @Override
    protected void onPause() {
        super.onPause();
        // when our activity pauses, we want to remove listening for location
        // updates
        myLocationOverlay.disableMyLocation();
    }
}

和错误日志:

07-31 09:35:34.227: E/AndroidRuntime(14613): FATAL EXCEPTION: main
07-31 09:35:34.227: E/AndroidRuntime(14613): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.captoom/ro.gebs.captoom.activities.LocationActivity}: java.lang.ClassNotFoundException: ro.gebs.captoom.activities.LocationActivity
07-31 09:35:34.227: E/AndroidRuntime(14613):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2034)
07-31 09:35:34.227: E/AndroidRuntime(14613):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
07-31 09:35:34.227: E/AndroidRuntime(14613):    at android.app.ActivityThread.access$700(ActivityThread.java:140)
07-31 09:35:34.227: E/AndroidRuntime(14613):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
07-31 09:35:34.227: E/AndroidRuntime(14613):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-31 09:35:34.227: E/AndroidRuntime(14613):    at android.os.Looper.loop(Looper.java:137)
07-31 09:35:34.227: E/AndroidRuntime(14613):    at android.app.ActivityThread.main(ActivityThread.java:4921)
07-31 09:35:34.227: E/AndroidRuntime(14613):    at java.lang.reflect.Method.invokeNative(Native Method)
07-31 09:35:34.227: E/AndroidRuntime(14613):    at java.lang.reflect.Method.invoke(Method.java:511)
07-31 09:35:34.227: E/AndroidRuntime(14613):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
07-31 09:35:34.227: E/AndroidRuntime(14613):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
07-31 09:35:34.227: E/AndroidRuntime(14613):    at dalvik.system.NativeStart.main(Native Method)
07-31 09:35:34.227: E/AndroidRuntime(14613): Caused by: java.lang.ClassNotFoundException: ro.gebs.captoom.activities.LocationActivity
07-31 09:35:34.227: E/AndroidRuntime(14613):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
07-31 09:35:34.227: E/AndroidRuntime(14613):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
07-31 09:35:34.227: E/AndroidRuntime(14613):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
07-31 09:35:34.227: E/AndroidRuntime(14613):    at android.app.Instrumentation.newActivity(Instrumentation.java:1068)
07-31 09:35:34.227: E/AndroidRuntime(14613):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2025)
07-31 09:35:34.227: E/AndroidRuntime(14613):    ... 11 more

请注意,如果这有所不同,我的构建也针对 Google API 平台......

编辑我排除了我也包含在我的项目中的谷歌播放服务库,错误日志更改为:

07-31 09:51:44.433: E/AndroidRuntime(14918): FATAL EXCEPTION: main
07-31 09:51:44.433: E/AndroidRuntime(14918): java.lang.NoClassDefFoundError: ro.gebs.captoom.activities.LocationActivity

谢谢!

4

2 回答 2

1

好吧 MapActivity 不再使用..试试这个例子。

谷歌地图

于 2013-07-31T06:48:20.777 回答
0

可能是它的构建路径配置问题。我也遇到过同样的问题。我做了以下解决问题。

1.Right click on your project and go to Java Build Path.

2.Click on Order and Export tab.

3.Check Android Private Libraries and other 3rd part libraries if you have added.

4.Press ok and clean the project.

我希望它能解决问题。

于 2013-07-31T07:16:19.767 回答