无法解析 Android 上的 MapActivity 类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3621163/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot resolve MapActivity class on Android
提问by John
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:
我有一个包含 11 个不同活动的应用程序。这些活动之一是 MapActivity 的扩展(它是用于数据可视化的地图)。要进入此活动,用户必须先浏览启动活动,然后再浏览其他 3 个活动。启动 MapActivity 的代码是:
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.
我确实将目标设置为 Google API,这是一个适用于 Android 1.5 的应用程序,并将 minsdk 指定为清单文件中的第 3 级。地图的使用库也在清单文件中。
<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.
我已经在这里呆了将近 2 天了,但没有任何结果。似乎有很多人在从其他活动启动 MapActivity 时遇到问题,但在任何地方都没有解决方案。有人有线索吗?谢谢。
采纳答案by John
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.
显然在某些时候我的构建环境真的一团糟。看起来我以某种方式在我的项目中两次使用了 google APIs jar,从而导致了冲突。我删除了该项目并重新创建了它,现在可以使用了。
回答by cyber-monk
The problem is that your MapVisclass is likely extending com.google.android.maps.MapActivity. For the system to be able to find this class you need to do two things:
问题是您的MapVis类可能扩展了com.google.android.maps.MapActivity。为了让系统能够找到这个类,你需要做两件事:
First make sure your project is including the Android maps.jarin your build path. From Eclipse find
首先确保您的项目在构建路径中包含 Android maps.jar。从 Eclipse 中找到
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:
然后选择适合您应用的“Google API”之一。您可以通过检查来确认 maps.jar 在您的构建路径中:
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:
第二次浏览到您的清单文件,并确保您将uses-library
代码片段嵌套在<application>
标签中,如下所示:
<manifest>
...
<application ...>
<uses-library android:name="com.google.android.maps" />
...
</application>
</manifest>
May the force be with you!
愿原力与你同在!
回答by Dan Harvey
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.
我在构建路径中手动添加了 maps.jar 并使用 android 2.1 作为目标。尽管我遵循的教程说要这样做,但这似乎不起作用(无论如何都不在 2.1 上)。
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
- 删除手动添加的 maps.jar 然后我将构建目标设置为 Google APIs 2.1 而不是 Android 2.1
I realised afterwards that the maps.jar is automatically included in the "Google" Android libs so was conflicting. :D
后来我意识到 maps.jar 会自动包含在“Google”Android 库中,因此存在冲突。:D
回答by Damien R.
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
我更新了网络僧侣的答案,因为问题不在于您没有 maps.jar,问题在于您有冲突的 jar(例如,您将 maps.jar 与 android 4.0 混合)。所以
- ensure that Google APIsis 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.propertiesand change the included libraries. (e.g with the latest android sdk, you will have:target=Google Inc.:Google APIs:14
) - go to
Project > Properties > Java Build Path > Libraries
and ensure that there is no android.jaror maps.jardirectly included. You should only have Google Apiswith at least maps.jarand android.jaras leaves.
- 确保已签入Google API
Project > Properties > Android
。如果不是这种情况,请选择它并单击应用。此更改将修改文件project.properties 中的目标属性并更改包含的库。(例如,使用最新的Android SDK中,你将有:target=Google Inc.:Google APIs:14
) - 转到
Project > Properties > Java Build Path > Libraries
并确保没有直接包含android.jar或maps.jar。您应该只拥有至少带有 maps.jar和android.jar作为叶子的Google API。
回答by Greta Radisauskaite
For those who are using Android studio and gradle:
对于那些使用 Android studio 和 gradle 的人:
- Completely remove maps.jar (and any other libs added for google maps) from dependencies.
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" />
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"
Clean and rebuild your project.
- 从依赖项中完全删除 maps.jar(以及为谷歌地图添加的任何其他库)。
在您的项目清单和地图库(如果您正在使用)模块中,在“应用程序”部分添加这一行:
< 使用库 android:name="com.google.android.maps" />
在您的项目 build.gradle 文件中(如果您正在使用,也在地图库 gradle 中)修改 compileSdkVersion:
compileSdkVersion "Google Inc.:Google APIs:19"
清理并重建您的项目。
回答by Matt Becker
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.
约翰的回答对我有用。我花了很长时间才找到这个解决方案。使用 MapActivity 的一个很棒的页面在这里。它涵盖了使用它时遇到的大多数问题,包括 John 的解决方案。
回答by biquillo
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
.
我遇到了同样的问题,我意识到您不能只将地图库添加到项目中,您必须将目标更改为类似的内容target=Google Inc.:Google APIs:8
而不是android=android-8
.
Anyway thanks you gave me the hint to discover it ;)
无论如何,谢谢你给了我发现它的提示;)
回答by overburn
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...
在您的 Android .jar 上右键单击构建路径-> 配置构建路径。然后,如果您看到 2 个 maps.jar 包括删除其中一个...
回答by kfeeney
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.
我遇到了同样的问题,并尝试了上述所有建议的解决方案(重建项目除外),但均未成功。然后我清理了项目并修复了它。在 Eclipse Project>Clean 检查您的项目并选择 OK。
回答by Yevgeny Simkin
in my case it turned out that the maps.jar was also sitting in my libs directory. Removing it from that fixed the issue.
在我的例子中,maps.jar 也位于我的 libs 目录中。从中删除它解决了问题。