Eclipse 中的 Java 项目:无法解析类型 java.lang.Object。它是从所需的 .class 文件间接引用的

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

Java project in Eclipse: The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files

javaeclipse

提问by Blue Diamond

I am getting the following error after importing a project in Eclipse:

在 Eclipse 中导入项目后出现以下错误:

The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files

无法解析 java.lang.Object 类型。它是从所需的 .class 文件间接引用的

However, I have set the path as C:\Program Files\Java\jdk1.6.0_41in Eclipse Kepler, through Window ? Preferences ? Java ? Installed JREs.

但是,我在 Eclipse Kepler 中通过Window将路径设置为C:\Program Files\Java\jdk1.6.0_41 ?喜好 ?爪哇?已安装 JRE

采纳答案by Gyro Gearless

This is an annoying Eclipse Bug which seems to bite now and then. See http://dev-answers.blogspot.de/2009/06/eclipse-build-errors-javalangobject.htmlfor a possible solution, otherwise try the following;

这是一个令人讨厌的 Eclipse 错误,它似乎不时咬人。有关可能的解决方案,请参阅http://dev-answers.blogspot.de/2009/06/eclipse-build-errors-javalangobject.html,否则请尝试以下操作;

  • Close the project and reopen it.
  • Clean the project (It will rebuild the buildpath hence reconfiguring with the JDK libraries)

    OR

  • Delete and Re-import the project and if necessary do the above steps again.

  • 关闭项目并重新打开它。
  • 清理项目(它将重建构建路径,从而使用 JDK 库重新配置)

    或者

  • 删除并重新导入项目,如有必要,请再次执行上述步骤。

The better cure is to try NetBeans instead of Eclipse :-)

更好的方法是尝试使用 NetBeans 而不是 Eclipse :-)

回答by Juned Ahsan

Object class is the base class for all the classes in java, if you are missing this it means you don't have the jdk libs in your buildpath. I don't know much about Kepler but you need to make sure it points to a correct jdk for compilation and a correct jre for running your java apps.

对象类是 Java 中所有类的基类,如果您缺少它,则意味着您的构建路径中没有 jdk 库。我对 Kepler 了解不多,但您需要确保它指向正确的 jdk 以进行编译,并指向正确的 jre 以运行您的 Java 应用程序。

However I have set the path as C:\Program Files\Java\jdk1.6.0_41 from eclipse Kepler toolbar->windows->preferences->java->installed jre

但是我已经将路径设置为 C:\Program Files\Java\jdk1.6.0_41 from eclipse Kepler toolbar->windows->preferences->java->installed jre

You are trying to point jdk instead of jre in your preferences. toolbar->windows->preferences->java->installed jre should point to a jre and not jdk.

您正试图在您的偏好中指向 jdk 而不是 jre。toolbar->windows->preferences->java->installed jre 应该指向一个 jre 而不是 jdk。

回答by Andy Zhang

Here is how I solved it: In Java-ADT: Windows - Preference - Java - Installed JREs Just add another JRE, pointing to the 'jre' folder under your JDK folder. (jre is included in the jdk). Make sure you chose the new jre.

这是我解决它的方法:在 Java-ADT 中:Windows - Preference - Java - Installed JREs 只需添加另一个 JRE,指向 JDK 文件夹下的“jre”文件夹。(jre 包含在 jdk 中)。确保您选择了新的 jre。

回答by Hyman Pettinger

None of the other answers worked for me. But doing this did:

其他答案都不适合我。但是这样做确实:

  1. Right click the project in the package explorer.
  2. Source > Clean up...
  3. Next > Finish
  1. 右键单击包资源管理器中的项目。
  2. 来源 > 清理...
  3. 下一步 > 完成

When I did this Eclipse added an import into one of my classes. I think this occurred because I saved my project with a missing import, probably rushing to get home after work.

当我这样做时,Eclipse 在我的一个类中添加了一个导入。我认为这是因为我保存了缺少导入的项目,可能是下班后赶回家。

回答by Ripon Al Wasim

The following steps could help:

以下步骤可能会有所帮助:

  1. Right-click on project ? Properties ? Java Build Path
  2. Select Librariestab
  3. Find the JRE System Library and remove it
  4. Click Add Library...button at right side ? Add the JRE System Library (Workspace default JRE)
  1. 右键单击项目? 特性 ?Java 构建路径
  2. 选择选项卡
  3. 找到 JRE 系统库并将其删除
  4. 单击右侧的Add Library...按钮?添加 JRE 系统库(工作区默认 JRE)

回答by satyrFrost

Another problem could be that the Android Project Build Target is not set.

另一个问题可能是未设置 Android 项目构建目标。

  1. Right-click the project
  2. Choose Properties
  3. Click Android
  4. Tick the appropriate Project Build Target
  5. Apply | OK
  1. 右键单击项目
  2. 选择属性
  3. 点击安卓
  4. 勾选适当的项目构建目标
  5. 申请 | 好的

回答by e18r

This happened to me when I imported a Java 1.8 project from Eclipse Luna into Eclipse Kepler.

当我将一个 Java 1.8 项目从 Eclipse Luna 导入 Eclipse Kepler 时,这发生在我身上。

  1. Right click on project > Build path > configure build path...
  2. Select the Libraries tab, you should see the Java 1.8 jre with an error
  3. Select the java 1.8 jre and click the Remove button
  4. Add Library... > JRE System Library > Next > workspace default > Finish
  5. Click OK to close the properties window
  6. Go to the project menu > Clean... > OK
  1. 右键单击项目>构建路径>配置构建路径...
  2. 选择 Libraries 选项卡,您应该会看到带有错误的 Java 1.8 jre
  3. 选择 java 1.8 jre 并单击 Remove 按钮
  4. 添加库... > JRE 系统库 > 下一步 > 工作区默认值 > 完成
  5. 单击确定关闭属性窗口
  6. 转到项目菜单 > 清理... > 确定

Et voilà, that worked for me.

等等,这对我有用。

回答by user989383

I was facing this issue with play-java application on eclipse after adding a controller, I removed and reinstalled JRE through build path and then removed and imported my project which solved this issue automatically. Thanks gyro.

添加控制器后,我在 eclipse 上的 play-java 应用程序遇到了这个问题,我通过构建路径删除并重新安装了 JRE,然后删除并导入了我的项目,自动解决了这个问题。谢谢陀螺。

回答by Sankalp

Right click on project -->Show in Navigator In navigator view you can see .classpath file, do delete this file and build the project. This worked for me. PS. If you have integrated you eclipse project with some version control like perfoce/svn , then unlinking the project before you delete the .classpath will be helpful.

右键单击项目 --> 在导航器中显示 在导航器视图中,您可以看到 .classpath 文件,删除此文件并构建项目。这对我有用。附注。如果您已经将 eclipse 项目与 perfoce/svn 等版本控制集成在一起,那么在删除 .classpath 之前取消链接项目会很有帮助。

回答by Jyo the Whiff

I had same problem in eclipse windows that I couldn't added dependant .class files from the JNI. In order resolve the same, I ported all the code to NetBeans IDE.

我在 eclipse 窗口中遇到了同样的问题,我无法从 JNI 添加依赖的 .class 文件。为了解决相同的问题,我将所有代码移植到 NetBeans IDE。

Can not add all the classes files from the JNI/JNA folder in Eclipse (JAVA, Windows 7)

无法在 Eclipse (JAVA, Windows 7) 中添加 JNI/JNA 文件夹中的所有类文件