February 10, 2005
Weird Eclipse error

I've come across the error message "The import somepackage cannot be resolved" loads of times - I'm sure that we all have. It usually means that you are missing a JAR file from your project's build path. But I'm getting it under strange circumstances this time...

The package that Eclipse is objecting to at the moment is in the current project! If I remove the import, and do an "Organise imports", Eclipse will replace the import, then claim not to be able to find it. If I hit F3 on the import, Eclipse takes me straight to the correct class.

Anyone got any ideas as to why Eclipse is claiming not to be able to resolve the import?

I have this problem running Eclipse version 3.1M4 and version 3.0.1, all on Windows 2000, with Java 1.4.2_1.

(I've also posted this to the eclipse.tools.jdt newsgroup - see Import cannot be resolved - for a class in my project!. You'll need a password before accessing this newsgroup.

Thanks in advance for all your recommendations that I switch to IntelliJ IDEA. ;-)

Posted to Java by Simon Brunning at February 10, 2005 01:17 PM

I've had that happening too and I've never quite understood what's really going on. It always seems like there's some sort of mismatch with the source folders defined in project's properties and what Eclipse thinks they are (at the moment), ie. not with project's libraries as such.

I've also always managed to somehow resolve it with some recombination of fiddling with project's properties (build path and source folders), refreshes and such, but not with any known procedure. So, no real help from me -- just acknowledging that you're not hallucinating. :-)

If only Eclipse's CVS import would automagically resolve build paths, libraries and source folders from build.xml, one could just delete the project and re-import it from the CVS. Unfortunately, this is not the case; CVS import is one of the most painful aspects of Eclipse. (There are some hacks around this flaw, but last I've checked they all were just that, cheesy hacks.)

Posted by: Jarno Virtanen on February 10, 2005 02:18 PM

Thanks for the moral support, Jarno. It's nice to know I'm not going mad. ;-)

I've tried a *huge* amount of aimless fiddling - including a whole new Eclipse install. Nothing seems to help.

Posted by: Simon Brunning on February 10, 2005 02:49 PM

Bit of a newbie also and just had the same (similar) thing happen while developing a Tapestry app, I had added into my classpath Jars tapestry-mock.jar & spring-mock.jar, all was fine then suddenly load of "Cannot be resolved" errors appeared, I've just removed them and added them back in and now Eclipse is happy. NFI why?

Posted by: Adam Henderson on February 17, 2005 10:23 PM

I just encountered this problem and resolved it by unlinking other projects I was referencing (in my main project's properties), applying the changes so that my main project completely broke, then rereferenced the other projects.

Anything that causes eclipse to rebuild it's index may work.

Posted by: Jonathan Kennedy on April 20, 2005 09:27 PM

I am also seeing this problem (Eclipse 3.1.0 build 200411050810) where the import was not found in a referenced project. Rebuilding and removing/readding references did not help. I "fixed" it by changing the reference to the output jar of the other project.

Posted by: Tim Shea on May 23, 2005 09:26 PM

I was having this problem as well. One of my classes was saying that it couldn't resolve another of my classes which was in the SAME package. So, I wasn't trying to import anything but eclipse still couldn't find my class. So, I noticed that the class that eclipse couldn't find didn't have the normal refactoring capabilities. In fact, when I tried to use refactor>rename on my class, I got an error message saying that this could only be used on a java class name. This led me to believe that somehow eclipse was thinking that my class was something else, so I created a new class and then copied all of my corrupt class into it and gave my new class the same name as the old class (after renaming the original of course). My build errors cleared right up. I don't know how eclipse thought that my original class wasn't a java class but this seemed to work as a workaround for me.

Posted by: Wesley Wright on May 25, 2005 02:44 PM

I take back my previous post. Recreating the class did not fix the problem for the long term. It is happening on my same class again now.

Posted by: Wesley Wright on May 25, 2005 02:48 PM

I have this problem too. Cleaning the project and doing an immediate build clears it up for a short time but it always comes back. Really annoying. I was hoping someone had figured it out, no luck.

Posted by: Matt McMahon on June 9, 2005 09:00 PM

I deleted my project definition and recreated it. That seemes to have resolved the problem.

Posted by: AR on June 20, 2005 11:55 PM

Solution: I faced the same problem and got it resolved by clicking on the 'clean' option in the 'project' menu. I'm using Eclipse 3.1.0

Posted by: Alagapan on June 23, 2005 06:06 PM

Solution confirmed: I faced the same problem and also got it resolved by clicking on the 'clean' option in the 'project' menu. I'm also using Eclipse 3.1.0

Posted by: Patrick Kimber on June 29, 2005 03:45 PM

Alternative solution: After using clean a hundred times or so without success, I used "Switch Workspace..." and selected my usual workspace (ie no changes). This caused Eclipse (3.1M7) to restart and hey presto all the problems had vanished.

Posted by: Gary Rowe on July 27, 2005 12:51 AM

Thanks for posting this question. I'm under a deadline and started having the same problem. I googled to your site and used the Project->Clean... solution. It worked beautifully!

Posted by: Steve Daly on July 28, 2005 08:10 PM

Neither clean nor switch workspace worked for me. The same package 'cannot resolves' went away after deleting, then re-creating the project.

Posted by: beeky on August 5, 2005 06:52 PM

This drove me *CRAZY*. I had to basically make sure that all classes in my JAR had the correct permissions first (chowned to the correct user), make sure the build path was correct in Eclipse... then, do the "switch workspace" trick (the "clean" trick didn't work).

The red "error" text was still showing on the import, but *wasn't* showing in the "problems" window in Eclipse. WTF ? I thought this was crazy, so tried to build the project, and it built fine. WTF ?
Then, I did a "switch workspace", and the red "error" text was gone.

There goes a good 2 hours of my life wasted away :)

Posted by: dylan on August 15, 2005 02:38 AM

Thank you! The "Clean..." menu item worked for me. I was baffled when I verified that the project built fine from the command line using ant.

Posted by: ian on August 25, 2005 10:39 PM

It worked fine for me the clean option ... I was surprised it happened, I did not change nothing since the last time, evrything was correctly set, it is really a bug ...

Posted by: Eric Nyssens on September 20, 2005 08:46 AM

I've cleaned many times, unlinked other projects, relinked them, restarted eclipse, switched workspaces, etc- still can't get the thing to build. Anybody have yet another solution?

Posted by: patrick on December 1, 2005 04:44 PM

I removed the source folder from the build path and then added it again. Eclipse is working fine now :)

Posted by: Ewerton Watanabe on December 19, 2005 06:02 PM

Stupid Eclipse is unhappy again...

Posted by: Ewerton Watanabe on December 20, 2005 08:28 PM

I also have this problem.

Eclipse SDK
Version: 3.1.2
Build id: M20060118-1600

Eclipse regularly seems to forget that imports exist. I find this happens a lot when I edit and then save a file in my project.

This happened to me when I used 3.1.0 and 3.1.1 on a different machine using a different OS also.

My work-around: remove and then add the JRE library

1. right-click on your project folder
2. click properties
3. click on the Libraries tab
4. click on the JRE
5. click remove
6. click OK
7. repeat 1-3
8. click Add library
9. click JRE ssystem library
10. click finish
11. click OK

This seems to refresh the build path and sort out the problem temporarily. You can be sure though that it will not go away for good. :(

Posted by: hands on March 21, 2006 11:31 AM

Project-Clean worked perfectly.

It seems that eclipse didn't like the .class that I have deleted just before the week end

Posted by: mamelouk on May 2, 2006 08:05 AM

The same problem and... the same solution. I used "clean" and "switch workspace" and I solve it.
Thank's to everybody

Posted by: Maya on May 18, 2006 08:27 AM

Thanks for posting this question. Still facing the same problem in '3.2.1' and the solution - 'clean' worked.

Posted by: kiran mova on April 5, 2007 07:40 PM

i had the same prob and it seemed like because the file mod date was in the past the class files wouldn't generate (they should though). i touched the whole dir and that triggered everything to build.

Posted by: rob munro on June 16, 2007 01:00 PM

Hmmm... I'm using Eclipse 3.2.2.

I get the problem whenever I add a .java file to the package and try to rebuild. Using the "clean" option does not make it go away.

I am able to resolve the issue by clicking on the appropriate package in the Package Explorer and hitting "F5" (Refresh). Alternately, I can right-click on the package and hit refresh. Subsequent builds seem to go smoothly without "The import ... cannot be resolved" error.

Posted by: K Chang on July 10, 2007 02:54 AM

I am having the problem and I know that it is because my project depends on other classes from other projects. My problem is that I have like 30 projects and it takes about 5 minutes to add each projects source to my new project. Is there no easier way?

Posted by: adam c on July 17, 2007 08:07 PM

Temporary Fixes Include:
1) Refresh Project
2) Close & Re-Open Project
3) Reorder Attached Jars/Libraries
4) Clean Project
5) Restart Eclipse
6) Any Combination of the Above

I do things in that general order because the faster fixes are toward the top, but it seems pretty random which ones will fix it, what combination works, or how long until it forgets that I still need those imports.

I hope Eclipse gets over this soon, it's a big waste of time and has caused some people to switch to a different IDE.

Posted by: Nick W on September 1, 2007 12:12 AM

Hi, I had the same problem but neither "clean" tip nor "restart Eclipse" tip worked. It seems that I had corrupted jars, when I fixed them the problem vanished :)

Posted by: AlNo on September 12, 2007 03:44 PM

I've also come across this problem and none of the options seems to result. I've even created a new project and copied all my files onto it without any success...

Posted by: Miguel A on September 28, 2007 12:15 PM

Thanks alot Mr.alagapan for the clean sollution.....


Posted by: RAJ on September 30, 2007 04:17 PM

Project -> clean worked perfect for me!

greetings from Portugal

Posted by: mleiria on October 17, 2007 05:13 PM

Project -> Clean... helped. Thnx!

Posted by: joshi on May 10, 2008 08:45 PM

Project-->Clean did not work for me. Hitting F5 (refresh) in the project explorer worked.

Posted by: mlavannis on May 16, 2008 03:44 AM

clean worked for me on Eclipse 3.2.2 thanks a lot

Posted by: daghan on June 6, 2008 11:49 AM

Switching workspaces to the one I was already using worked great! Thank you, Simon Brunning and Gary Rowe

Posted by: Milburn Young on August 1, 2008 07:52 AM

Project->clean worked for me.
(eclipse Version: 3.4.1)


Posted by: amoise on November 14, 2008 08:07 PM

I found a solution to a case of this problem where non of the above solutions worked. My project has several sub source directories or the project root dir:


(the usual way is src/java/com... only). This is a large existing project and cannot be changed (thousands of classes). When I created the project in eclipse it would split the class files between scr, com, and java, and I had more than 100k errors about imports not being resolved. To resolve this I removed the com and java folders from the project build path:

1) right clock on project and selcet properties
2) selct java build path
3) in the source tab remove any folders other than the root one (so i removed java and come and left src)
4) do a clean and rebuild

I hope this helps other people, done with eclipse 3.4.0

Posted by: Heath on December 2, 2008 06:43 PM

Project-->Clean worked for me. Thanks for the solution.

Posted by: Mamatha on January 7, 2009 05:09 PM

Wow this is a stupid issue. Project -> Clean also worked for me. Thanks for the post and solutions.

Posted by: Jake on January 28, 2009 02:58 PM

Heath -> Thank's a lot. I had this problem and manged to solve it earlier by adding the sources. Now I solved it by removing the sources as your prescription describes. Using Eclipse 3.4.1.

I notices one thing; this happens after I have used Ant...

For you reference, this solved it this time:

1) right clock on project and select properties
2) selct java build path
3) in the source tab remove any folders other than the root one (so i removed java and come and left src)
4) do a clean and rebuild


Posted by: Niklas on February 10, 2009 07:29 PM
Post a comment

Email Address:



Remember info?