7

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.

joanna
  • 743
  • 3
  • 13
  • 27

2 Answers2

1

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.

Heiko Rupp
  • 30,426
  • 13
  • 82
  • 119
  • I just didn't post my whole manifest, but the package declaration was ok. Smth else was causing the problem. Thank you for your answer anyway – joanna May 01 '11 at 16:27
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">
rekaszeru
  • 19,130
  • 7
  • 59
  • 73
  • It works now, thanks. Didn't even cross my mind that this was the problem, as I've read in Manning's 'Android in Action' that the absence of the dot sometimes leads to many hours in debugging...and that it should always be there. – joanna May 01 '11 at 16:29
  • 1
    Right, if it is missing from the launcher/main activity. I did debug several hours though, until fount out, that the other activities don't need it, except if they are in an inner package, like `com.adm.activities`. Then you should Declare it as `android:name=".activities.AddLocation"`. +1 for the question, hopefully it will help others too! – rekaszeru May 01 '11 at 16:32
  • 2
    I was see the same problem, NoClassDefFondError when trying to explicitly launch a MapActivity Intent. However, the "." in the manifest didn't seem to have any effect. My problem was that I was missing the "" line in my manifest. +1 for the clarification on using it with "inner-packages", though. – plainjimbo May 22 '11 at 22:46
  • Even after adding uses library for maps. I had same issue. Then i found that i was adding maps.jar explicitly and i was using google api as default android sdk. I believe which already includes maps. Kind of duplication i guess. Its weird that it was showing error on activity class! – Vijay Krishna Jun 06 '11 at 15:23