Eclipse中的Java项目:Java .lang类型。对象不能被解决。它间接引用自所需的.class文件

时间:2021-05-05 05:32:35

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

. lang类型。对象不能被解决。它间接引用自所需的.class文件

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

然而,我已经设置路径C:\Program Files\Java\ jdk1.6.0_41开普勒在Eclipse中,通过菜单窗口»»偏好»Java»安装jre。

16 个解决方案

#1


215  

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.html for a possible solution, otherwise try the following;

这是一个令人讨厌的Eclipse Bug,它似乎时不时会产生问题。查看http://dev-answers.blogspot.de/2009/06/eclipse-build-error -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:-)

#2


186  

The following steps could help:

以下步骤可以帮助:

  1. Right-click on project » Properties » Java Build Path
  2. 右键单击项目»属性»Java构建路径。
  3. Select Libraries tab
  4. 选择库选项卡
  5. Find the JRE System Library and remove it
  6. 找到JRE系统库并删除它
  7. Click Add Library... button at right side » Add the JRE System Library (Workspace default JRE)
  8. 单击Add图书馆…右侧按钮»添加JRE系统库(工作空间默认JRE)

#3


10  

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中,安装的JREs仅仅添加了另一个JRE,指向JDK文件夹下的“JRE”文件夹。(jre包含在jdk中)。确保您选择了新的jre。

#4


7  

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

当我从Eclipse Luna导入Java 1.8项目到Eclipse Kepler时,我就遇到了这种情况。

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

Et voilà, that worked for me.

这对我很有效。

#5


5  

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 lib。我不太了解开普勒,但您需要确保它指向用于编译的正确jdk和用于运行java应用程序的正确jre。

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工具栏- >窗口- >首选项- > java - >安装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。工具栏->窗口->偏好->java->安装jre应该指向jre而不是jdk。

#6


4  

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

其他答案对我都不起作用。但这样做了:

  1. Right click the project in the package explorer.
  2. 右键单击package explorer中的项目。
  3. Source > Clean up...
  4. 源>清理…
  5. Next > Finish
  6. Next >完成

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在我的一个类中添加了一个导入。我认为发生这种情况是因为我保存了一个丢失的导入,可能是下班后匆忙赶回家。

#7


3  

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

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

  1. Right-click the project
  2. 右键单击项目
  3. Choose Properties
  4. 选择属性
  5. Click Android
  6. 点击安卓
  7. Tick the appropriate Project Build Target
  8. 标记适当的项目构建目标。
  9. Apply | OK
  10. 应用|好吧

#8


3  

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.

右键单击project——>显示在Navigator视图中的.classpath文件中,请删除该文件并构建项目。这为我工作。如果您已经将eclipse项目与perfoce/svn等版本控制集成在一起,那么在删除.classpath之前将项目取消链接将会很有帮助。

#9


2  

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,然后删除并导入我的项目,自动解决了这个问题。谢谢陀螺。

#10


2  

This seems to be an Eclipse bug, though restarting Eclipse worked great for me, hope this helps somebody else too.

这似乎是一个Eclipse bug,尽管重新启动Eclipse对我很有用,但希望这也能帮助其他人。

#11


2  

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. I fixed JAVA_HOME as well

这在Windows中是一个众所周知的问题。我还修复了JAVA_HOME

2) I java 7 and java 8 on my laptop. So I defined the jvm using eclipse.ini. This is not a mandatory step if you don't have -vm entry in your eclipse.ini. I updated:

我的笔记本电脑上有java 7和java 8。所以我使用eclipse.ini定义了jvm。如果在eclipsee .ini中没有-vm条目,这不是必须的步骤。我更新:

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

Instead of:

而不是:

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

Good luck

祝你好运

#12


2  

No amount of cleaning, closing/reopening the project&IDE, removing/adding the JRE in build path worked for me.

再多的清理、关闭/重新打开项目和ide、删除/添加构建路径中的JRE都对我有用。

The only 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. That worked.

我找到的唯一解决方案是从Eclipse(而不是从磁盘)删除项目,从磁盘中删除项目的Eclipse文件,然后再次导入Eclipse。这工作。

It is easily done if you are using Maven:

如果您使用Maven,这很容易做到:

mvn clean eclipse:clean eclipse:eclipse

#13


2  

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. 右键单击项目->构建路径->配置构建路径。
  3. Go to 'Libraries' tab
  4. 去“库”选项卡
  5. Add Library -> JRE System Library -> Next -> Workspace default JRE (or you can Choose Alternate JRE form your System) -> Finish
  6. 添加Library -> JRE系统库-> ->工作空间默认JRE(或者您可以从系统中选择替代JRE) -> Finish

if Yes than .

如果是比。

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

#14


1  

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 windows中,我遇到了同样的问题,我无法添加依赖于JNI的类文件。为了解决相同的问题,我将所有代码移植到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文件夹中添加所有的类文件

#15


1  

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. 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.

当我们使用tomcat 6和jdk 1.8版本时,一些特性将不起作用,您将得到的这个错误就是其中之一。您需要在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 -> add ->标准VM ->(在jre home,放置jdk path) ->完成

now clean and check the project

现在清理并检查项目

#16


0  

Happend to me after I've installed some updates in eclipse but forgot to restart afterwards. So maybe restarting eclipse might help.

当我在eclipse中安装了一些更新,但是之后忘记了重新启动。因此,重新启动eclipse可能会有所帮助。

#1


215  

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.html for a possible solution, otherwise try the following;

这是一个令人讨厌的Eclipse Bug,它似乎时不时会产生问题。查看http://dev-answers.blogspot.de/2009/06/eclipse-build-error -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:-)

#2


186  

The following steps could help:

以下步骤可以帮助:

  1. Right-click on project » Properties » Java Build Path
  2. 右键单击项目»属性»Java构建路径。
  3. Select Libraries tab
  4. 选择库选项卡
  5. Find the JRE System Library and remove it
  6. 找到JRE系统库并删除它
  7. Click Add Library... button at right side » Add the JRE System Library (Workspace default JRE)
  8. 单击Add图书馆…右侧按钮»添加JRE系统库(工作空间默认JRE)

#3


10  

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中,安装的JREs仅仅添加了另一个JRE,指向JDK文件夹下的“JRE”文件夹。(jre包含在jdk中)。确保您选择了新的jre。

#4


7  

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

当我从Eclipse Luna导入Java 1.8项目到Eclipse Kepler时,我就遇到了这种情况。

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

Et voilà, that worked for me.

这对我很有效。

#5


5  

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 lib。我不太了解开普勒,但您需要确保它指向用于编译的正确jdk和用于运行java应用程序的正确jre。

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工具栏- >窗口- >首选项- > java - >安装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。工具栏->窗口->偏好->java->安装jre应该指向jre而不是jdk。

#6


4  

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

其他答案对我都不起作用。但这样做了:

  1. Right click the project in the package explorer.
  2. 右键单击package explorer中的项目。
  3. Source > Clean up...
  4. 源>清理…
  5. Next > Finish
  6. Next >完成

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在我的一个类中添加了一个导入。我认为发生这种情况是因为我保存了一个丢失的导入,可能是下班后匆忙赶回家。

#7


3  

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

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

  1. Right-click the project
  2. 右键单击项目
  3. Choose Properties
  4. 选择属性
  5. Click Android
  6. 点击安卓
  7. Tick the appropriate Project Build Target
  8. 标记适当的项目构建目标。
  9. Apply | OK
  10. 应用|好吧

#8


3  

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.

右键单击project——>显示在Navigator视图中的.classpath文件中,请删除该文件并构建项目。这为我工作。如果您已经将eclipse项目与perfoce/svn等版本控制集成在一起,那么在删除.classpath之前将项目取消链接将会很有帮助。

#9


2  

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,然后删除并导入我的项目,自动解决了这个问题。谢谢陀螺。

#10


2  

This seems to be an Eclipse bug, though restarting Eclipse worked great for me, hope this helps somebody else too.

这似乎是一个Eclipse bug,尽管重新启动Eclipse对我很有用,但希望这也能帮助其他人。

#11


2  

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. I fixed JAVA_HOME as well

这在Windows中是一个众所周知的问题。我还修复了JAVA_HOME

2) I java 7 and java 8 on my laptop. So I defined the jvm using eclipse.ini. This is not a mandatory step if you don't have -vm entry in your eclipse.ini. I updated:

我的笔记本电脑上有java 7和java 8。所以我使用eclipse.ini定义了jvm。如果在eclipsee .ini中没有-vm条目,这不是必须的步骤。我更新:

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

Instead of:

而不是:

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

Good luck

祝你好运

#12


2  

No amount of cleaning, closing/reopening the project&IDE, removing/adding the JRE in build path worked for me.

再多的清理、关闭/重新打开项目和ide、删除/添加构建路径中的JRE都对我有用。

The only 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. That worked.

我找到的唯一解决方案是从Eclipse(而不是从磁盘)删除项目,从磁盘中删除项目的Eclipse文件,然后再次导入Eclipse。这工作。

It is easily done if you are using Maven:

如果您使用Maven,这很容易做到:

mvn clean eclipse:clean eclipse:eclipse

#13


2  

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. 右键单击项目->构建路径->配置构建路径。
  3. Go to 'Libraries' tab
  4. 去“库”选项卡
  5. Add Library -> JRE System Library -> Next -> Workspace default JRE (or you can Choose Alternate JRE form your System) -> Finish
  6. 添加Library -> JRE系统库-> ->工作空间默认JRE(或者您可以从系统中选择替代JRE) -> Finish

if Yes than .

如果是比。

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

#14


1  

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 windows中,我遇到了同样的问题,我无法添加依赖于JNI的类文件。为了解决相同的问题,我将所有代码移植到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文件夹中添加所有的类文件

#15


1  

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. 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.

当我们使用tomcat 6和jdk 1.8版本时,一些特性将不起作用,您将得到的这个错误就是其中之一。您需要在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 -> add ->标准VM ->(在jre home,放置jdk path) ->完成

now clean and check the project

现在清理并检查项目

#16


0  

Happend to me after I've installed some updates in eclipse but forgot to restart afterwards. So maybe restarting eclipse might help.

当我在eclipse中安装了一些更新,但是之后忘记了重新启动。因此,重新启动eclipse可能会有所帮助。