Android活动类未找到异常

时间:2013-07-31 06:42:49

标签: android android-activity android-manifest

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

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

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

请告诉我我的错误。

Android Manifest:

<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>

LocationActivity类:

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平台...

编辑我排除了我的项目中也包含的Google Play服务库,错误日志更改为:

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

谢谢!

2 个答案:

答案 0 :(得分:1)

不再使用MapActivity了。试试这个例子。

Google Maps

答案 1 :(得分: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.

我希望它能解决问题。