Eclipse 不再可以自动导入 java 类

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

Eclipse no longer can auto import java Classes

javaeclipseide

提问by greedybuddha

A few days ago my eclipse stopped being able to auto import classes. So usually when I have a class I'm using, like BufferedReader, that I need to import I simply hit ctrl+shift+Oand the imports magically appear. But now, basic imports like List or Scanner just sit there all squiggly and red. I have the 1.6JRE included as part of my project, and when I manually import them they will then work.

几天前,我的 Eclipse 无法自动导入类。所以通常当我有一个我正在使用的类时,比如 BufferedReader,我需要导入我只需点击ctrl+ shift+O并且导入会神奇地出现。但是现在,像 List 或 Scanner 这样的基本导入只是坐在那里,全部呈波浪状和红色。我将 1.6JRE 作为我项目的一部分包含在内,当我手动导入它们时,它们就会起作用。

This is a huge annoyance and time sink now. I'm open to any suggestions to fix the problem.

现在这是一个巨大的烦恼和时间。我愿意接受任何解决问题的建议。

回答by Jim Garrison

I have seen this behavior before. Sometimes just closing and reopening Eclipse resolves it. Sometimes I have had to recreate the project from the source, which can be painful if you have a lot of dependencies and you're not using Maven. You should also do a File/Refresh at the top level to make sure you're in sync with the filesystem

我以前见过这种行为。有时只需关闭并重新打开 Eclipse 即可解决。有时我不得不从源代码重新创建项目,如果您有很多依赖项并且您没有使用 Maven,这可能会很痛苦。您还应该在顶层执行 File/Refresh 以确保您与文件系统同步

回答by Juned Ahsan

  1. Try restoring the default options in 'Windows > Preferences > Java > Editor > Content Assist > Advanced'.

  2. If it does not work, try to create a new workspace and it may solve your problem

  1. 尝试恢复“Windows > Preferences > Java > Editor > Content Assist > Advanced”中的默认选项。

  2. 如果它不起作用,请尝试创建一个新的工作区,它可能会解决您的问题

Hope it helps!

希望能帮助到你!

回答by Jag

Try cleaning your project. I fixed mine by cleaning the project.

尝试清理您的项目。我通过清理项目来修复我的。

回答by hshin

In my case, cleaning just a project didn't fix but clean all project did.

就我而言,只清理一个项目并没有解决问题,但清理所有项目都解决了。