Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse no longer can auto import java Classes

Tags:

java

eclipse

ide

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+O and 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.

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

like image 237
greedybuddha Avatar asked May 03 '13 00:05

greedybuddha


People also ask

How do I enable auto import in Eclipse?

As you type a class name, press Ctrl+Space to bring up Eclipse's autocomplete. Once you press Enter to select it, Eclipse will automatically add an import for the class.

Why import option is not working in Eclipse?

Go to Preferences » Java » Editor » Content Assist » Advanced. Make sure Other Java Proposals is ticked/checked. If that does not work simply close the project and reopen it.

How do I fix all imports in Eclipse?

Go to the line of unused import, press Ctrl + 1, which is an Eclipse shortcut of a quick fix. This will show a drop-down menu to fix this error and one of them will be “remove unused imports.” It will remove that import statement from the Java file.


2 Answers

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

like image 141
Jim Garrison Avatar answered Oct 05 '22 02:10

Jim Garrison


  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

Hope it helps!

like image 25
Juned Ahsan Avatar answered Oct 05 '22 03:10

Juned Ahsan