John
John

Reputation: 529

Cannot resolve MapActivity class on Android

I have an application which has 11 different activities. One of these activities is an extension of MapActivity (it is a map for data visualization). To get to this activity the user must first travel through the launch activity, then 3 other activities. The code to launch the MapActivity is:

Intent i = new Intent(getBaseContext(), MapVis.class);
i.putExtra("edu.uml.cs.isense.visualizations.session_list", sessions);
startActivity(i);

When this is executed I get the following output from the Log:

09-01 14:36:22.389: WARN/dalvikvm(592): Class resolved by unexpected DEX: Ledu/uml/cs/isense/visualizations/MapVis;(0x44981910):0x128260 ref [Lcom/google/android/maps/MapActivity;] Lcom/google/android/maps/MapActivity;(0x44981910):0x13d330
09-01 14:36:22.389: WARN/dalvikvm(592): (Ledu/uml/cs/isense/visualizations/MapVis; had used a different Lcom/google/android/maps/MapActivity; during pre-verification)
09-01 14:36:22.389: WARN/dalvikvm(592): Unable to resolve superclass of Ledu/uml/cs/isense/visualizations/MapVis; (118)
09-01 14:36:22.389: WARN/dalvikvm(592): Link of class 'Ledu/uml/cs/isense/visualizations/MapVis;' failed
09-01 14:36:22.389: DEBUG/AndroidRuntime(592): Shutting down VM
09-01 14:36:22.389: WARN/dalvikvm(592): threadid=1: thread exiting with uncaught exception (group=0x4001d7f0)
09-01 14:36:22.399: ERROR/AndroidRuntime(592): FATAL EXCEPTION: main
09-01 14:36:22.399: ERROR/AndroidRuntime(592): java.lang.NoClassDefFoundError: edu.uml.cs.isense.visualizations.MapVis
09-01 14:36:22.399: ERROR/AndroidRuntime(592):     at edu.uml.cs.isense.visualizations.Visualizations.onOptionsItemSelected(Visualizations.java:213)
09-01 14:36:22.399: ERROR/AndroidRuntime(592):     at android.app.Activity.onMenuItemSelected(Activity.java:2195)
09-01 14:36:22.399: ERROR/AndroidRuntime(592):     at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:730)
09-01 14:36:22.399: ERROR/AndroidRuntime(592):     at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143)
09-01 14:36:22.399: ERROR/AndroidRuntime(592):     at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855)
09-01 14:36:22.399: ERROR/AndroidRuntime(592):     at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:532)
09-01 14:36:22.399: ERROR/AndroidRuntime(592):     at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)
09-01 14:36:22.399: ERROR/AndroidRuntime(592):     at android.view.View$PerformClick.run(View.java:8816)
09-01 14:36:22.399: ERROR/AndroidRuntime(592):     at android.os.Handler.handleCallback(Handler.java:587)
09-01 14:36:22.399: ERROR/AndroidRuntime(592):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-01 14:36:22.399: ERROR/AndroidRuntime(592):     at android.os.Looper.loop(Looper.java:123)
09-01 14:36:22.399: ERROR/AndroidRuntime(592):     at android.app.ActivityThread.main(ActivityThread.java:4627)
09-01 14:36:22.399: ERROR/AndroidRuntime(592):     at java.lang.reflect.Method.invokeNative(Native Method)
09-01 14:36:22.399: ERROR/AndroidRuntime(592):     at java.lang.reflect.Method.invoke(Method.java:521)
09-01 14:36:22.399: ERROR/AndroidRuntime(592):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-01 14:36:22.399: ERROR/AndroidRuntime(592):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-01 14:36:22.399: ERROR/AndroidRuntime(592):     at dalvik.system.NativeStart.main(Native Method)
09-01 14:36:22.399: ERROR/AndroidRuntime(592): Caused by: java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
09-01 14:36:22.399: ERROR/AndroidRuntime(592):     at dalvik.system.DexFile.defineClass(Native Method)
09-01 14:36:22.399: ERROR/AndroidRuntime(592):     at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:209)
09-01 14:36:22.399: ERROR/AndroidRuntime(592):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:203)
09-01 14:36:22.399: ERROR/AndroidRuntime(592):     at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
09-01 14:36:22.399: ERROR/AndroidRuntime(592):     at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
09-01 14:36:22.399: ERROR/AndroidRuntime(592):     ... 17 more
09-01 14:36:22.409: WARN/ActivityManager(92):   Force finishing activity edu.uml.cs.isense/.visualizations.Visualizations
09-01 14:36:22.909: WARN/ActivityManager(92): Activity pause timeout for HistoryRecord{44c84a90 edu.uml.cs.isense/.visualizations.Visualizations}

I do have the target set to Google APIs, this is an app meant for Android 1.5, and specifies the minsdk to be level 3 in the manifest file. uses-library for maps is also in manifest file.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="edu.uml.cs.isense"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.CONTROL_LOCATION_UPDATES"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".Isense" 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=".experiments.Experiments" android:label="@string/app_name_experiments"/>
  <activity android:name=".sessions.Sessions" android:label="@string/app_name"/>
  <activity android:name=".people.People" android:label="@string/app_name_people"/>
  <activity android:name=".profile.Profile" android:label="@string/app_name"/>
  <activity android:name=".sensors.Sensors" android:label="@string/app_name_sensors"/>
  <activity android:name=".visualizations.DataTable" android:label="@string/app_name"/>
  <activity android:name=".visualizations.Visualizations" android:label="@string/app_name"/>
  <activity android:name=".sensors.DataListActivity"
                  android:label="@string/selectFile"
                  android:theme="@android:style/Theme.Dialog"
                  android:configChanges="orientation|keyboardHidden" />
        <activity android:name=".sensors.Upload" android:label="@string/app_name_uploader"/>
        <activity android:name=".visualizations.MapVis" android:label="@string/app_name"
            android:theme="@android:style/Theme.NoTitleBar" />
        <uses-library android:name="com.google.android.maps"/>
</application>
    <uses-sdk android:minSdkVersion="3"/>
</manifest>

I have been at this for almost 2 days now with no results. It seems that there are a lot of people having issues launching a MapActivity from other activities but there are no solutions anywhere. Does anyone have a clue? Thanks.

Upvotes: 37

Views: 42050

Answers (12)

Greta Radisauskaite
Greta Radisauskaite

Reputation: 276

For those who are using Android studio and gradle:

  1. Completely remove maps.jar (and any other libs added for google maps) from dependencies.
  2. In your projects manifest and in your maps-library (if you are using one) module add this line in 'application' section:

    < uses-library android:name="com.google.android.maps" />

  3. In your projects build.gradle file (and also in maps library gradle if you are using one) modify compileSdkVersion:

    compileSdkVersion "Google Inc.:Google APIs:19"

  4. Clean and rebuild your project.

Upvotes: 3

Fred Ondieki
Fred Ondieki

Reputation: 2494

One other most probable reason as it turned out was the fact that there were conflicting libs ,so resulting into those ClassLoading issues,it is good to remove the other unneccessary libs. If you have included the google maps Lib as suggested by previous contributors then do remove them,so that your project now looks like the following below.

enter image description here

enter image description here

Another Possible Cause is the package declaration on your manifest . enter image description here

Upvotes: 0

Yevgeny Simkin
Yevgeny Simkin

Reputation: 28349

in my case it turned out that the maps.jar was also sitting in my libs directory. Removing it from that fixed the issue.

Upvotes: 1

Damien R.
Damien R.

Reputation: 191

I update cyber-monk answer because the problem is not that you do not have maps.jar, the problem is that you have conflicting jar (e.g you mix maps.jar with android 4.0). So

  1. ensure that Google APIs is checked in Project > Properties > Android. If that not the case select it and click on apply. This change will modify the target property in the file project.properties and change the included libraries. (e.g with the latest android sdk, you will have: target=Google Inc.:Google APIs:14)
  2. go to Project > Properties > Java Build Path > Libraries and ensure that there is no android.jar or maps.jar directly included. You should only have Google Apis with at least maps.jar and android.jar as leaves.

Upvotes: 5

shawalli
shawalli

Reputation: 597

@cyber-monk's (sorry, can't comment on answers yet) answer is similar to every other answer on the internet, except that it shows one very important detail that most leave out. You have to put the tag within the tag. Most just say to put it in the manifest without saying WHERE to put it. I put it inside and finally, FINALLY got it to work

Upvotes: 0

Dan Harvey
Dan Harvey

Reputation: 798

I had this exact same problem.

I was adding the maps.jar manually in the build path and using android 2.1 as the target. This does not seem to work (not on 2.1 anyway) despite the tutorial i followed saying to do it like this.

How i solved it was:

-Remove the manually added maps.jar then i set my build target to Google APIs 2.1 instead of Android 2.1

I realised afterwards that the maps.jar is automatically included in the "Google" Android libs so was conflicting. :D

Upvotes: 13

Matt Becker
Matt Becker

Reputation: 2368

John's answer worked for me. It took me forever to come across this solution. A great page for working with the MapActivity is here. It covers most of the problems encountered when working with it, including the solution John had.

Upvotes: 2

kfeeney
kfeeney

Reputation: 959

I was having the same issue and tried all the above proposed solutions (except rebuilding the project) with no success. Then I cleaned the project and it was fixed. In Eclipse Project>Clean check your project and select ok.

Upvotes: 1

cyber-monk
cyber-monk

Reputation: 5560

The problem is that your MapVis class is likely extending com.google.android.maps.MapActivity. For the system to be able to find this class you need to do two things:

First make sure your project is including the Android maps.jar in your build path. From Eclipse find

Project > Properties > Android

Then select one of the "Google APIs" as appropriate for you app. You can confirm that maps.jar is on your build path by checking:

Project > Properties > Java Build Path > Libraries > Expand "Google Apis"

Second browse to your manifest file and make sure you have the uses-library snippet nested within the <application> tags as follows:

<manifest>
...
   <application ...>
      <uses-library android:name="com.google.android.maps" />
      ...
   </application>
</manifest>

May the force be with you!

Upvotes: 65

overburn
overburn

Reputation: 21

try this:

on your Android .jar right click Build Path-> Configure Build Path. then if you see 2 maps.jar includes remove one of them...

Upvotes: 2

biquillo
biquillo

Reputation: 6539

I had the same problem and I realized you cannot just add the map library to the project, you have to change the target to something like this target=Google Inc.:Google APIs:8 instead of android=android-8.

Anyway thanks you gave me the hint to discover it ;)

Upvotes: 2

John
John

Reputation: 529

Apparently at some point my build environment got really messed up. It looked like I somehow had the google APIs jar in my project twice, causing a conflict. I deleted the project and recreated it, works now.

Upvotes: 16

Related Questions