简体   繁体   English

Eclipse:“无法解析导入 java.io”

[英]Eclipse: "The import java.io cannot be resolved"

I have several Android projects in Eclipse, and all is fine, except one (a library) that can not resolve any imports.我在 Eclipse 中有几个 Android 项目,一切都很好,除了一个(库)无法解析任何导入。

The java.io imports do resolve fine in other Android projects in the same workspace, and previously (I haven't used it for over a year) this library worked fine, too. java.io 导入在同一工作区中的其他 Android 项目中确实可以很好地解决,并且以前(我也没有使用它超过一年)这个库工作得很好。

Any ideas?有任何想法吗?

Check two things 检查两件事

Eclipse preferences Eclipse首选项

  1. Check your Eclipse preferences: Java -> Installed JREs 检查Eclipse首选项: Java - > Installed JREs
  2. The one that you're using should be marked and it should be a JDK not just a JRE. 您正在使用的那个应该被标记,它应该是JDK而不仅仅是JRE。

Project build path 项目构建路径

  1. Also check your project's build path: Right click on the project -> Properties -> Java Build Path 还要检查项目的构建路径:右键单击项目 - > Properties - > Java Build Path
  2. Check in the libraries folder whether the JRE System Library is present and ... 检查libraries文件夹中是否存在JRE系统库并且...
  3. If not add it using Add library -> JRE System Library and then select the correct one (from an installed JDK). 如果不是使用Add library - > JRE System Library添加它,然后选择正确的(从已安装的JDK)。

The following worked for me: 以下对我有用:

  • Close the project and reopen it. 关闭项目并重新打开它。

OR 要么

  • Clean the project ( = rebuilds the buildpath and thereby reconfigures the JDK libraries). 清理项目(=重建构建路径,从而重新配置JDK库)。

I am using Maven an this is what I did to re-solve --> 我正在使用Maven这是我所做的重新解决 - >

  1. Right click on project 右键单击项目
  2. Maven -> Update Project. Maven - >更新项目。 Make sure you choose 'Force update of Snapshots/Releases'. 确保选择“强制更新快照/版本”。
  3. Also check the 'clean project', 'update project conf from pom' and 'refresh workspace resource options' and click ok. 还要检查“清理项目”,“从pom更新项目conf”和“刷新工作区资源选项”,然后单击“确定”。

I was missing the JRE Systems Library in my Project Tree. 我错过了项目树中的JRE系统库。 And navigating to Projects' Build Path and 'Add(ing) Library' worked! 导航到Projects的Build Path和'Add(ing)Library'工作!

I just ran into this problem with Eclipse 2022-6 and java-17-openjdk-amd64.我刚刚用 Eclipse 2022-6 和 java-17-openjdk-amd64 遇到了这个问题。 I just appeared during editing in another file, the same code had worked before.我刚刚在另一个文件中编辑时出现,相同的代码之前已经工作过。

For me, all settings were correct and none of the above tricks worked.对我来说,所有设置都是正确的,上述技巧都没有奏效。 What I then did was completely removing the import command import java.io.Closeable;然后我所做的是完全删除导入命令import java.io.Closeable; , saving the file, adding the same import command back at the same place, and saving again. ,保存文件,在同一位置添加相同的导入命令,然后再次保存。 The error disappeared.错误消失了。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM