7

我正在尝试使用显式意图在我的 android 应用程序中显示 MapView。虽然我没有发现我的代码有任何问题,但当我尝试开始我的活动时,我不断收到“NoClassDefFoundError”。基本上,从我的主要活动(SetCriteria)中,我在用户按下按钮时创建了明确的意图:

 Log.i(TAG, "Showing map..");
 try{
   Intent intentMap = new Intent(view.getContext(), AddLocation.class);
   startActivity(intentMap);
}catch(Throwable ex) {
   Log.e(TAG, "Error occured while trying to display map", ex);
}

我的 LogCat 显示:

 java.lang.NoClassDefFoundError: com.adm.AddLocation
 ...
 Caused by: java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation

我的清单如下所示:

<application android:label="@string/app_name" android:icon="@drawable/ic_launcher_red">
    <uses-library android:name="com.google.android.maps"/>              
    <activity android:name=".SetCriteria"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>        
    <activity android:name=".AddLocation" 
          android:label="@string/add_location">         
    </activity>
</application>

我只有一个包:com.adm。那么有什么问题呢?我使用 Intent(Intent.ACTION_VIEW, uri) 启动地图没有问题,但我希望我的特定活动处理地图。

4

2 回答 2

1

从清单片段中不清楚您定义了什么包。

您需要将其放在顶级清单元素中:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.adm"
          >

    <application android:icon="@drawable/icon" android:label="@string/app_name" ...

如果不添加,系统将不会使用包,并且您的活动“ .AddLocation”将以没有类的“AddLocation”结束,这与com.adm.AddLocation.

于 2011-05-01T14:29:02.687 回答
1

您应该在第二个活动声明中删除.您的类名之前的“”(点),所以它看起来像:

<activity android:name="AddLocation" android:label="@string/add_location">
于 2011-05-01T14:56:24.600 回答