Android Explicit Intent会抛出NoClassDefFound错误

joa*_*nna 7 maps android explicit android-intent

我正在尝试使用显式意图在我的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);
}
Run Code Online (Sandbox Code Playgroud)

我的LogCat显示:

 java.lang.NoClassDefFoundError: com.adm.AddLocation
 ...
 Caused by: java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
Run Code Online (Sandbox Code Playgroud)

我的清单看起来像这样:

<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>
Run Code Online (Sandbox Code Playgroud)

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

rek*_*eru 1

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

<activity android:name="AddLocation" android:label="@string/add_location">
Run Code Online (Sandbox Code Playgroud)

  • 当尝试显式启动 MapActivity Intent 时,我看到了同样的问题,NoClassDefFondError。但是,那 ”。” 清单中似乎没有任何效果。我的问题是我的清单中缺少“&lt;uses-library android:name="com.google.android.maps"/&gt;”行。不过,+1澄清了将其与“内部包”一起使用的情况。 (2认同)