James B
James B

Reputation: 293

Eclipse won't generate import statements, stopped showing Quick Fix suggestions

My Eclipse installation suddenly stopped showing import suggestions. If I type a class name that isn't in the current package, autocomplete works fine and shows the class, but after picking from the drop-down, the class name is highlighted as an error with the message "MyClass cannot be resolved to a variable". This error shows no Quick Fix suggestions. However, if I manually add the relevant import statement at the top of the file, the code compiles and runs fine.

I've checked my build path and everything appears to be in order -- and like I said, the code runs when I hand-jam the import statement -- but losing automatic importing is really slowing me down. Any idea what could have gone wrong? It worked fine last week!

ETA: Another note, if it helps: F3 still opens the class declaration, so Eclipse clearly knows what I "mean", even without the import statement.

Also also: Things that have not helped:

Upvotes: 5

Views: 7093

Answers (4)

James B
James B

Reputation: 293

Thanks for all the help, everybody, but this turns out to have been a case of a broken Eclipse install.

I still haven't figured out exactly how or what was broken, but I tried to make a new project with a single "Hello World" class. The New Class wizard errored out with "Creation of element failed" in the class org.eclipse.wst.jsdt.internal.core.dom.rewrite.ImportRewriteAnalyzer. Once I hit "internal errors" in Eclipse, I gave up and installed a fresh Eclipse from a new download.

With a new Eclipse, I got my Quick Fix suggestions back, as well as automatic imports. I guess in future I'll try reinstalling Eclipse before I go looking for solutions to obscure errors like this :-/

Upvotes: 4

everag
everag

Reputation: 7672

If none of the other answers works, one brute force suggestion which sometimes resolves weird issues like this would be:

  1. Close your Eclipse
  2. Delete the .metadata folder inside your Workspace folder
  3. Restart Eclipse

Note: This way you're going to lose all your workspace configuration. I advise you to backup it first in case it doesn't works.

Upvotes: 0

William Morrison
William Morrison

Reputation: 11006

Clean all your projects. Then update Eclipse. Then restart of Eclipse. Then restart your development PC.

This happens to me sometimes too, I follow these steps and the problem always goes away.

Upvotes: 0

Narendra Pathai
Narendra Pathai

Reputation: 41945

These kind of situations can occur if your workspace went into a bad state or eclipse was unable to properly save state during last exit of workspace.

Try Project > Clean and clean all projects and rebuild all. See if this helps.

Upvotes: 3

Related Questions