Android Explicit Intent throws NoClassDefFound error

青春壹個敷衍的年華 提交于 2019-12-22 05:17:23

问题


I'm trying to use an explicit intent to display a MapView in my android app. Although I don't see anything wrong with my code, I keep getting a "NoClassDefFoundError" when I try to start my activity. Basically, from my main activity (SetCriteria), I create the explicit intent when user presses a button :

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

My LogCat displays:

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

My Manifest looks like this:

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

I have only one package: com.adm. So what could be wrong? I have no problem launching a map by using Intent(Intent.ACTION_VIEW, uri) but I want my specific activity dealing with the map.


回答1:


You should remove the "." (dot) before your class name in the second activity declaration, so it would look like:

<activity android:name="AddLocation" android:label="@string/add_location">



回答2:


From the manifest snippet it is not clear, what package you have defined.

You need to put it in the top-level manifest element:

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

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

If you do not add that, the system will not use a package and your activity ".AddLocation" will end as "AddLocation" without a class, which is not the same as com.adm.AddLocation.



来源:https://stackoverflow.com/questions/5848769/android-explicit-intent-throws-noclassdeffound-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!