简体   繁体   English

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

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

I am getting the following error after importing a project in Eclipse:在 Eclipse 中导入项目后出现以下错误:

The type java.lang.Object cannot be resolved. java.lang.Object 类型无法解析。 It is indirectly referenced from required .class files它是从所需的 .class 文件中间接引用的

However, I have set the path as C:\Program Files\Java\jdk1.6.0_41 in Eclipse Kepler, through Window » Preferences » Java » Installed JREs .但是,我通过Window » Preferences » Java » Installed JREs在 Eclipse Kepler 中将路径设置为C:\Program Files\Java\jdk1.6.0_41

This is an annoying Eclipse Bug which seems to bite now and then.这是一个恼人的 Eclipse 错误,它似乎时不时地咬人。 See http://dev-answers.blogspot.de/2009/06/eclipse-build-errors-javalangobject.html for a possible solution, otherwise try the following;有关可能的解决方案,请参阅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)清理项目(它将重建构建路径,因此重新配置 JDK 库)

    OR或者

  • Delete and Re-import the project and if necessary do the above steps again.删除并重新导入项目,如有必要,请再次执行上述步骤。

The better cure is to try NetBeans instead of Eclipse :-)更好的解决方法是尝试 NetBeans 而不是 Eclipse :-)

The following steps could help:以下步骤可能会有所帮助:

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

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.以下是我解决它的方法: 在 Java-ADT 中:Windows - 首选项 - Java - 安装的 JRE 只需添加另一个 JRE,指向 JDK 文件夹下的“jre”文件夹。 (jre is included in the jdk). (jre 包含在 jdk 中)。 Make sure you chose the new jre.确保您选择了新的 jre。

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选择 Libraries 选项卡,您应该会看到带有错误的 Java 1.8 jre
  3. Select the java 1.8 jre and click the Remove button选择 java 1.8 jre 并单击 Remove 按钮
  4. Add Library... > JRE System Library > Next > workspace default > Finish添加库... > JRE 系统库 > 下一步 > 工作区默认值 > 完成
  5. Click OK to close the properties window单击确定关闭属性窗口
  6. Go to the project menu > Clean... > OK转到项目菜单>清理...>确定

Et voilà, that worked for me.等等,这对我有用。

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.对象类是 java 中所有类的基类,如果您缺少它,则意味着您的构建路径中没有 jdk 库。 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.我对 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 从 eclipse Kepler 工具栏->windows->preferences->java->installed jre

You are trying to point jdk instead of jre in your preferences.您试图在您的首选项中指向 jdk 而不是 jre。 toolbar->windows->preferences->java->installed jre should point to a jre and not jdk. toolbar->windows->preferences->java->installed jre 应该指向一个 jre 而不是 jdk。

Have you installed a different version JRE after , while using previous version of JRE in Eclipse .在 Eclipse 中使用以前版本的 JRE 之后,您是否安装了不同版本的 JRE。

if Not than :如果不大于:

  1. Right click on your project -> Build Path -> Configure Build Path右键单击您的项目 -> 构建路径 -> 配置构建路径
  2. Go to 'Libraries' tab转到“库”选项卡
  3. Add Library -> JRE System Library -> Next -> Workspace default JRE (or you can Choose Alternate JRE form your System) -> Finish添加库 -> JRE 系统库 -> 下一步 -> 工作区默认 JRE(或者您可以从系统中选择备用 JRE)-> 完成

if Yes than .如果是比。

  1. Right click on your project -> Build Path -> Configure Build Path右键单击您的项目 -> 构建路径 -> 配置构建路径
  2. Go to 'Libraries' tab转到“库”选项卡
  3. Remove Previous Version删除以前的版本
  4. Add Library -> JRE System Library -> Next -> Workspace default JRE (or you can Choose Alternate JRE from your System) -> Finish添加库 -> JRE 系统库 -> 下一步 -> 工作区默认 JRE(或者您可以从系统中选择备用 JRE)-> 完成

This seems to be an Eclipse bug, though restarting Eclipse worked great for me, hope this helps somebody else too.这似乎是一个 Eclipse 错误,虽然重新启动 Eclipse 对我很有用,希望这对其他人也有帮助。

Edit: the next time I had this problem the solution above did not work - the problem was that the imported project I had - had the wrong java runtime set - which was not present (I had java 8 in my JRE present, but the project imported was set to Java 11, so I had to change the project java version to 8. Alternative would be to add more JRE's in the Eclipse preferences - if the project really needs a newer JRE to work)编辑:下次我遇到这个问题时,上面的解决方案不起作用 - 问题是我导入的项目 - 有错误的 java 运行时集 - 不存在(我的 JRE 中有 java 8,但项目导入的设置为 Java 11,因此我不得不将项目 Java 版本更改为 8。替代方法是在 Eclipse 首选项中添加更多 JRE - 如果项目确实需要更新的 JRE 才能工作)

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下一步 > 完成

When I did this Eclipse added an import into one of my classes.当我这样做时,Eclipse 将导入添加到我的一个类中。 I think this occurred because I saved my project with a missing import, probably rushing to get home after work.我认为这是因为我保存了缺少导入的项目,可能下班后急于回家。

Right click on project -->Show in Navigator In navigator view you can see .classpath file, do delete this file and build the project.右键单击项目 --> 在导航器中显示 在导航器视图中,您可以看到 .classpath 文件,删除此文件并构建项目。 This worked for me.这对我有用。 PS. 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.如果您已将 eclipse 项目与 perfoce/svn 等版本控制集成,那么在删除 .classpath 之前取消链接项目将很有帮助。

No amount of cleaning, closing/reopening the project&IDE, removing/adding the JRE in build path worked for me.没有多少清理、关闭/重新打开项目和 IDE、在构建路径中删除/添加 JRE 对我有用。

The solution I found was to remove the project from Eclipse (not from disk), remove the project's Eclipse files from the disk, and import into Eclipse again.我找到的解决方案是从 Eclipse(而不是磁盘)中删除项目,从磁盘中删除项目的 Eclipse 文件,然后再次导入 Eclipse。 That worked.那行得通。

It is even faster if you are using Maven:如果您使用 Maven,它会更快:

  1. Close Eclipse (no need to remove the project)关闭 Eclipse(无需删除项目)
  2. Run mvn clean eclipse:clean eclipse:eclipse运行mvn clean eclipse:clean eclipse:eclipse
  3. Open Eclipse.打开 Eclipse。 Your project is still present and the problem should be gone.您的项目仍然存在,问题应该消失了。

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好的

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

What solved my problem was to解决我的问题是

1) Install the jdk under directory with no spaces: 1)安装jdk目录下不带空格:

C:/Java

Instead of代替

C:/Program Files/Java

This is a known issue in Windows.这是 Windows 中的一个已知问题。 I fixed JAVA_HOME as well我也修复了JAVA_HOME

2) I java 7 and java 8 on my laptop. 2)我在笔记本电脑上安装了 java 7 和 java 8。 So I defined the jvm using eclipse.ini .所以我使用eclipse.ini定义了 jvm。 This is not a mandatory step if you don't have -vm entry in your eclipse.ini .如果eclipse.ini中没有-vm条目,这不是强制性步骤。 I updated:我更新了:

C:/Java/jdk1.7.0_79/jre/bin/javaw.exe

Instead of:代替:

C:/Java/jdk1.7.0_79/bin/javaw.exe

Good luck祝你好运

I had the similar problem.我有类似的问题。 It was a maven project with the following snippet of pom.xml.这是一个带有以下 pom.xml 片段的 maven 项目。

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <release>9</release>
            </configuration>
        </plugin>
        </plugins>
    </build>

I had to change the following.我不得不更改以下内容。

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <release>11</release>
            </configuration>
        </plugin>
        </plugins>
    </build>

If you have already installed JDK 11 and working with java 9 or java 10 as maven compiler, eclipse can not detect.如果您已经安装了 JDK 11 并使用 java 9 或 java 10 作为 maven 编译器,则 eclipse 无法检测到。 Hence change the release to 11 or the actual installed version of JDK.因此将发行版更改为 11 或实际安装的 JDK 版本。

I had same problem in eclipse windows that I couldn't added dependant .class files from the JNI.我在 Eclipse 窗口中遇到了同样的问题,我无法从 JNI 添加依赖的 .class 文件。 In order resolve the same, I ported all the code to NetBeans IDE.为了解决同样的问题,我将所有代码移植到 NetBeans IDE。

Can not add all the classes files from the JNI/JNA folder in Eclipse (JAVA, Windows 7) 无法在 Eclipse 中添加 JNI/JNA 文件夹中的所有类文件(JAVA,Windows 7)

While we are working with tomcat 6 and jdk 1.8 versions, some of the features will not work and this error you are getting is one.当我们使用 tomcat 6 和 jdk 1.8 版本时,某些功能将无法使用,而您遇到的这个错误就是其中之一。 you need to change the jdk version to stable version(preferable jdk 1.6 or jdk 1.8_65) in eclipse to resolve this error.您需要在 eclipse 中将 jdk 版本更改为稳定版本(首选 jdk 1.6 或 jdk 1.8_65)以解决此错误。

in eclipse step 1: properties -> java build path -> jre system library(remove) step 2: add -> jre system library -> alternate jre -> installed jre -> add -> Standard VM -> (in jre home, place jdk path) -> finish在 Eclipse 步骤 1:属性 -> java 构建路径 -> jre 系统库(删除)步骤 2:添加 -> jre 系统库 -> 备用 jre -> 安装的 jre -> 添加 -> 标准 VM -> (在 jre 主页中,放置jdk路径)->完成

now clean and check the project现在清理并检查项目

I got this error because I have installed "Eclipse IDE for Enterprise Java Developers", I uninstalled this and installed "Eclipse IDE for Java Developers".我收到此错误是因为我安装了“面向企业 Java 开发人员的 Eclipse IDE”,我卸载了它并安装了“面向 Java 开发人员的 Eclipse IDE”。 Problem solved for me.问题为我解决了。

It's working for me after unchecking 'User '--releae option' in eclipse Java-compiler在 Eclipse Java 编译器中取消选中“用户”--releae 选项后,它对我有用

In eclipse step 1: properties -> java Complier -> uchecking 'User '--releae option' option -> finish在 Eclipse 步骤 1 中:属性 -> java Complier -> uchecking 'User '--releae option' 选项 -> 完成

Java version 13.0.1 Eclipse version : Eclipse IDE for Enterprise Java Developers. Java 版本 13.0.1 Eclipse 版本:面向企业 Java 开发人员的 Eclipse IDE。

Happend to me after I've installed some updates in eclipse but forgot to restart afterwards.在我在 Eclipse 中安装了一些更新但之后忘记重新启动后发生在我身上。 So maybe restarting eclipse might help.所以也许重新启动 Eclipse 可能会有所帮助。

However trivial this might be, check your Java installation.无论这多么微不足道,请检查您的 Java 安装。 For me, rt.jar was missing .对我来说, rt.jar 不见了

I found this after fiddling for half a day with Eclipse settings and getting nowhere.我在 Eclipse 设置中摆弄了半天却一无所获后发现了这一点。 Desperate, I finally decided to try compiling the project from the command line.无奈之下,我终于决定尝试从命令行编译项目。 I wasn't expecting to see anything wrong since I thought it's an Eclipse issue but to my astonishment I saw this:我没想到会出现任何问题,因为我认为这是一个 Eclipse 问题,但令我惊讶的是,我看到了这个:

Error occurred during initialization of VM
java/lang/NoClassDefFoundError: java/lang/Object

I don't know what happened to my Java installation and where did rt.jar go.我不知道我的 Java 安装发生了什么以及 rt.jar 去了哪里。 Anyway this comes as a reminder to go through the fail checklist and tick all the boxes no matter how unbelievable they are.无论如何,这提醒您检查失败清单并勾选所有框,无论它们多么令人难以置信。 It would have saved me a lot of time.它会为我节省很多时间。

Right click on project, select Maven -> Update project.右键单击项目,选择 Maven -> 更新项目。 That should solve the issue.那应该可以解决问题。

In my case it was a big modular project and the ' red X ' was showing only in the parent project.就我而言,这是一个大型模块化项目,“红色 X ”仅在父项目中显示。 I went to the parent project我去了父项目

Properties -> Built Path属性 -> 构建路径

a removed the JRE Library there, just that, no JRE Library on the parent project anymore. a 删除了那里的 JRE 库,就这样,父项目上不再有 JRE 库了。

None of these solutions worked for me.这些解决方案都不适合我。 In my case the problem was that I had some Java code producing .java files and I had accidentally created a file called Class.java (content doesn't seem to matter).就我而言,问题是我有一些 Java 代码生成.java文件,并且我不小心创建了一个名为Class.java的文件(内容似乎无关紧要)。 Removing the file fixed the problem.删除文件解决了问题。

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 从 eclipse Kepler 工具栏->windows->preferences->java->installed jre

If you have already added JRE and still showing error.如果您已经添加了 JRE 并且仍然显示错误。 try follow尝试关注

right click on your project右键单击您的项目

project->build path-> configure build path -> java build path -> libraries tab -> select JRE system library and click edit button -> If alternative JRE is selected choose workspace default JRE.项目->构建路径->配置构建路径-> java构建路径->库选项卡->选择JRE系统库并单击编辑按钮->如果选择了替代JRE,则选择工作区默认JRE。

this is how my error gone.这就是我的错误消失的方式。

sometimes this error happened after updating JAVA.有时更新 JAVA 后会发生此错误。 if so go to eclipse.ini file in the same folder where eclipse existed.如果是这样,请转到存在 Eclipse 的同一文件夹中的 eclipse.ini 文件。 then change the line under -vm keyward to the new path of jre/bin folder to get the path go to programfiles -> java -> jre latest version -> bin folder copy the path and replace in line under -vm keyword.然后将 -vm keyward 下的行更改为 jre/bin 文件夹的新路径以获取路径转到 programfiles -> java -> jre 最新版本 -> bin 文件夹复制路径并替换 -vm 关键字下的行。

This error message occurs when a class/java-project is unable to resolve correct JDK libraries.当类/java-project 无法解析正确的 JDK 库时,会出现此错误消息。 Say, in my primary Project A, I was getting this error.比如说,在我的主要项目 A 中,我遇到了这个错误。 This Project A had a maven dependency for a project B. Project B pointed to JDK-11.这个项目 A 对项目 B 有一个 Maven 依赖项。项目 B 指向 JDK-11。 Project A pointed to JDK-9项目 A 指向 JDK-9

Correction I did : Made Project also point to JDK-11.我所做的更正:Made Project 也指向 JDK-11。 It resolved the issue for me它为我解决了这个问题

For Gradle users, use eclipse plugin.对于 Gradle 用户,请使用 eclipse 插件。 I'm not using eclipse directly but jdtls on Neovim.我不是直接使用 eclipse,而是在jdtls上使用 jdtls。 This solves the issue for me.这为我解决了这个问题。

build.gradle构建.gradle

plugins {
    id 'java'
    id 'eclipse'
}

Then run然后运行

gradle cleanEclipse eclipse

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法解析类型 java.lang.Object。 它是从 required.class 文件中间接引用的 - The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files 无法解析类型java.lang.Object。 它是从必需的.class文件间接引用的。Eclipse Mars Mac OS X El Capitan错误 - The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files Error on Eclipse Mars Mac OS X El Capitan java.lang.Object无法解析。 从所需的.class文件间接引用它 - java.lang.Object can not be resolved. It is indirectly referenced from required .class files Eclipse中的错误(适用于Android):无法解析java.lang.String类型。它是从所需的.class文件间接引用的 - Error in Eclipse (for Android): The type java.lang.String cannot be resolved. It is indirectly referenced from required .class files 无法解析类型java.lang.Charsequence。 它是从required.class文件间接引用的 - The type java.lang.Charsequence cannot be resolved. It is indirectly referenced from required.class files Eclipse jdk 11问题:java.lang.String类型无法解析。 它是从 required.class 文件中间接引用的 - Eclipse jdk 11 problem: The type java.lang.String cannot be resolved. It is indirectly referenced from required .class files 无法解析java.lang.CharSequence类型。 它是从所需的.class文件间接引用的 - The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files 无法解析类型java.lang.Charsequence。 从所需的.class文件间接引用 - The type java.lang.Charsequence cannot be resolved. It is indirectly referenced from required .class file 无法解析java.rmi.RemoteException类型。 它是从java中所需的.class文件错误中间接引用的 - The type java.rmi.RemoteException cannot be resolved. It is indirectly referenced from required .class files error in java 第7行的“ yyy.jspf”错误:无法解析类型java.lang.CharSequence。 从所需的.class文件间接引用它 - Error in “yyy.jspf” at line 7: The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM