Java Android Eclipse Classpath - 想要添加类路径容器路径但 eclipse 不会让我

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1095322/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 23:39:11  来源:igfitidea点击:

Android Eclipse Classpath - want to add classpath container path but eclipse won't let me

javaandroideclipseclasspath

提问by mikemaccana

I'm using Eclipse to learn to develop Android applications in Java. I haven't used Eclipse before.

我正在使用 Eclipse 来学习用 Java 开发 Android 应用程序。我以前没有使用过 Eclipse。

The project I'm trying to use (supplied by OReilly as part of 'Android Application Development') is MJAndroid. When attempting to run the project, the Run fails, and the Problems tab mentions com.java.Object can't be found, and Eclipse asks me to check the build path. Clicking Properties -> Java Build Path -> Libraries, the message 'Unable to get system library for the project' is displayed.

我尝试使用的项目(由 OReilly 作为“Android 应用程序开发”的一部分提供)是 MJAndroid。尝试运行项目时,运行失败,问题选项卡提到无法找到 com.java.Object,Eclipse 要求我检查构建路径。单击属性-> Java 构建路径-> 库,显示消息“无法获取项目的系统库”。

On a working project, Properties -> Java Build Path -> Libraries has an entry for Android 1.1, which if I click Edit, has the classpath container path of com.android.ide.eclipse.adt.ANDROID_FRAMEWORK.

在一个工作项目中,Properties -> Java Build Path -> Libraries 有一个 Android 1.1 条目,如果我单击 Edit,它的类路径容器路径为 com.android.ide.eclipse.adt.ANDROID_FRAMEWORK。

It seems a simple matter of adding the correct container path to my non-working project. However Eclipse seems determined to make this as difficult as possible. No matter what I chose to add - jars, externals jars, variables, libraries, class folders, external class folders, nothing seems to take the form of 'com.android.ide.eclipse.adt.ANDROID_FRAMEWORK' that the 'Android 1.1' entry on the working app has.

将正确的容器路径添加到我的非工作项目似乎很简单。然而 Eclipse 似乎决心让这一切变得尽可能困难。无论我选择添加什么 - 罐子、外部罐子、变量、库、类文件夹、外部类文件夹,似乎没有任何东西采用“Android 1.1”的“com.android.ide.eclipse.adt.ANDROID_FRAMEWORK”形式工作应用程序上的条目有。

How can I add this namespace to my project so it resembles the working one?

如何将此命名空间添加到我的项目中,使其类似于工作的命名空间?

I'm quite sure it's a problem with Eclipse's somewhat odd user interface. Frankly there' nothing I'd prefer more than a file to modify and set such information - my background is in Python, and the whole eclipse environment seems an unnecessary burden.

我很确定这是 Eclipse 有点奇怪的用户界面的问题。坦率地说,我更喜欢一个文件来修改和设置这些信息——我的背景是 Python,整个 eclipse 环境似乎是一个不必要的负担。

采纳答案by Shreedhar Kotekar

I had faced the same issue when I imported a sample code downloaded from the internet. I am using android sdk 1.5 with 0.9 ADT plugins. Here is a simpler way to fix the andoid library reference issues

当我导入从 Internet 下载的示例代码时,我遇到了同样的问题。我正在使用带有 0.9 ADT 插件的 android sdk 1.5。这是修复andoid库引用问题的更简单方法

  • Right click on the project which has issues and select properties
  • Select the appropriate Android build (1.1, 1.5 or 1.5 with google api) and say ok
  • Again right click on the project and select "Android Tools > Fix Project Properties"
  • Fix the imports once (if required)
  • Refresh the project and you should be ready to go without any manual editing
  • 右键单击有问题的项目并选择属性
  • 选择适当的 Android 版本(1.1、1.5 或 1.5 与 google api)并说 ok
  • 再次右键单击项目并选择“Android 工具 > 修复项目属性”
  • 修复一次导入(如果需要)
  • 刷新项目,您应该准备好开始,无需任何手动编辑

回答by willz

I would verify you have the correct version of Java installed as well as the Android SDK. I would recommend installing/reinstalling the ADT plugin in your eclipse, makes it alot easier to create the android project.

我会验证您是否安装了正确版本的 Java 以及 Android SDK。我建议在你的 eclipse 中安装/重新安装 ADT 插件,这样可以更容易地创建 android 项目。

http://developer.android.com/sdk/1.5_r2/installing.html

http://developer.android.com/sdk/1.5_r2/installing.html

回答by Rich Seller

Sometimes Eclipse can get a bit funny (technical term) with classpath container resolution. You have a working project in your workspace, so you can rule out plugin installation issues. You could try opening the .classpathfile (hidden by default, select the triangle in the top-right of the Package Explorer view, select Filters...and uncheck .* resources) and manually adding the container declaration.

有时 Eclipse 会因类路径容器解析而变得有点有趣(技术术语)。您的工作区中有一个工作项目,因此您可以排除插件安装问题。您可以尝试打开.classpath文件(默认情况下隐藏,选择 Package Explorer 视图右上角的三角形,选择Filters...并取消选中.* resources)并手动添加容器声明。

`<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>`

You may then have to close the project and open it again (right-click->Close Project) before Eclipse recognises the change.

在 Eclipse 识别更改之前,您可能必须关闭项目并再次打开它(右键单击 -> 关闭项目)。

You may also find that there is an Android builder and/or nature. If you compare the .project files for the working and non-working versions you may see entries for Android builders/natures. Copying the relevant entries may resolve the issue.

您可能还会发现有一个 Android 构建器和/或性质。如果您比较工作和非工作版本的 .project 文件,您可能会看到 Android 构建器/自然条目。复制相关条目可能会解决该问题。

回答by Abhishek Susarla

Also. I guess the path of the Android SDK must be setup correctly. This happened when I was overloaded with projects and I decided to create a new workspace copying some existing stuff into it.

还。我猜必须正确设置Android SDK的路径。这发生在我的项目超载时,我决定创建一个新的工作区,将一些现有的东西复制到其中。

Seems that the new workspace requires you to setup these details too once again

似乎新工作区也需要您再次设置这些详细信息

Is that setup properly?

这样设置正确吗?

回答by odiggity

Had the same problem and it turns out the Android SDK Location was not set which was a really simple fix. Go to Window->Preferences, click on 'Android' on the left hand menu, fill in the location of the Android SDK (e.g. C:\Program Files\Android\android-sdk) and click OK. Everything worked fine for me after that.

遇到了同样的问题,结果发现未设置 Android SDK 位置,这是一个非常简单的修复。转到Window->Preferences,点击左侧菜单中的'Android',填写Android SDK 的位置(例如C:\Program Files\Android\android-sdk)并点击OK。在那之后,一切对我来说都很好。

Found the answer in this set up guide: http://developer.motorola.com/docstools/library/Installing-Android-Dev-Environment/

在此设置指南中找到答案:http: //developer.motorola.com/docstools/library/Installing-Android-Dev-Environment/

回答by Stark

I faced this same problem after importing a project through GIT. The problem was that I didn't have the same target android platform installed, and the build path somehow got corrupted.

通过 GIT 导入项目后,我遇到了同样的问题。问题是我没有安装相同的目标 android 平台,并且构建路径以某种方式被破坏了。

The first obvious thing i did was changing the target sdk in the project.properties, but even after cleaning up the project and Android Tools > Fix Project Properties, it didn't help and I was still getting the build error.

我做的第一件明显的事情是更改 project.properties 中的目标 sdk,但即使在清理项目和 Android 工具 > 修复项目属性之后,它也没有帮助,我仍然收到构建错误。

My solution after wasting close to 1 hour trying to figure this out?

在浪费了将近 1 个小时试图弄清楚这一点后,我的解决方案是什么?

RESTART ECLIPSE

Everything worked fine after that. Eclipse is pretty fickle. Only through years of experience you'll then understand her well. :)

之后一切正常。Eclipse 非常善变。只有通过多年的经验,你才能很好地了解她。:)

回答by Luis Slocker

sometimes, eclipse can help you. In Android projects, click right button on the project-> Android Tools -> Fix Project Properties.

有时,eclipse 可以帮助你。在Android项目中,点击项目右键->Android工具->修复项目属性。

It's usefull in class path errors!!

它在类路径错误中很有用!!

Luck!

运气!