问题
I hit F5 ~1000 times and restarted eclipse (also with -clean), deleted /bin, but nothing helps. Manually importing DoodleClient does not help. DoodleClient exists and is perfectly fine, everything worked before. Clicking on "Import 'DoodleClient' ..." does nothing.
What I did before this problem occured:
- I added *.class to .gitignore
git rm *.class
- On the next pull, hunderts of .class files were deleted by git

回答1:
Alternatively, you can highlight the project :
Choose Clean ...
from Project menu and if you have activated the Build Automatically
option (in the same menu), the classes will be generated anew.
回答2:
I could resolve it: On another project (from the same git repo), I had the same issue on several files in different packages. All I had to do was writing a white-space into the file, remove it again and save, so eclipse would re-compile it (I guess).
Some kind of a strange behaviour... :S
回答3:
I got the same error in Maven project. Running Maven Clean and closing the project and reopening didn't work for me. Right click project -> Maven -> Update Project worked for me.
回答4:
I tried to refresh the workspace (F5) and clean the project, but that did not do the trick. What worked for me was to right-click on the project and select 'Close Project'.
Once closed I re-opened the project. This seemed to refresh all the files for the project in Eclipse.
回答5:
Luckily I didn't have 1000's of errors; for my 20+ class resolution problems, what I did was to:
- Delete a part of the name of the offending class
- Place cursor at the end (of remaining fragment of class' name), do an auto-suggest (Ctrl+space) and choose the correct class from the suggestions
- Save
Tedious but it worked....
回答6:
The first thing I would do is create a new class in the same package and check if it is visible from this class where you have the issue.
Also I'm not sure but you could check to change the name of your class "D" for something different.
and ...Check if the file actually does exist
回答7:
I had the same problem. I tried to add the statement with the static method call again and delete the old one. Eclipse even helped me with auto-completion and after that it underlined the statement again. In my case closing the project and importing it again after that worked.
回答8:
I have 3 projects in my project explorer and they have dependencies on each other.
They all went nuts and I had 9000+ errors across all 3 projects.
It turned out that cleaning each of them in the correct order (middle, top, bottom) resolved everything.
Cleaning in the correct order is what fixed my issue.
Just thought it was worth mentioning :)
回答9:
Compiler checks dependencies on compiled files, not on source code. So it means the compiler doesn't file DoodleClient.class.
To check if you have the compiled class, open the Navigator view (Window -> Show View -> Navigator
) and look for the directory that contains the .class files (usually bin/<project>
or target/classes
for Maven) and check if you have there DoodleClient.class file. If you don't you can:
- check the .classpath file to see if DoodleClient.java appears in some
excluding
attribute in some classpathentry (delete it from the exclusion attribute if it does) - if you are using Maven check if DoodleClient.java appears in an <exclude></exclude> tag in the pom.xml
- copy the necessary java files/packages to some other folder on your disk, compile DoodleClient.java manually from dos console with javac and then copy DoodleClient.class in your class folder in your project. Hope this helps.
回答10:
I have the same issue every day, and the solution is different every time. :) You can try something like these:
- Project menu - Clean
- Project - Maven - Update project (Alt+F5)
- Project - Refresh
- Project - Run as - Maven clean
- Project - Run as - Maven install
- Restart Eclipse
- Remove application from servlet container (if it is web app)
- Pray.. :)
回答11:
Right click on project then R-click on Maven then Update Project
回答12:
None of the things above worked.
However I could fix it like this:
- Installed a new Eclipse Version
- Opened a new workspace
- Cloned my Maven projects from my Git repo into the new workspace
- Imported them in Eclipse as Maven Projects
Result: Eclipse finds classes again.
回答13:
In my case, the DoodleClient class had all its lines commented. It is not the way i wrote the class, it was a side effect of solving improperly a SVN conflict. So if you just ran an update on your project, you might perhaps want to check again the contents of your file.
回答14:
Tried many of the suggestions above w/o success (Eclipse restart, Clean multiple times, auto-suggest etc.). What got me out of this bind was a hard reset to a prior commit (I'm using git), building (this time w/ success), then pulling the latest sources of the project again and rebuilding.
回答15:
In my case it was that my Java Build Path -> Source didn't had checked the Contains test sources on my include source path and my code was JUnit
来源:https://stackoverflow.com/questions/11568855/why-cant-eclipse-resolve-class-in-same-package