Eclipse “Import cannot be resolved” error
by Sherif
I’m amazed at how many shortcuts or different ways there are of doing things in Eclipse.
Recently I kept hitting an issue of Eclipse not recognising my imports (even though they were there). I was always getting the message:
import ClassName cannot be resolved.
Where ClassName was my imported class. I’m using the MyEclipse Workbench 5.5.1 on Eclipse 3.2. Here are a few tips on how you can fix this (some worked for me, some didn’t):
- ‘Clean’ Your Eclipse Project: Go to Project > Clean in Eclipse [This seems to work for me]
- Refresh your project folder (right click on your project > refresh)
- Re-build your project
- Clean your builds (If using Ant or Maven – clean your builds)
- Recreate your project in Eclipse
- ‘Switch’ Workspace – then Switch back (Eg Change to Debug, then switch back to Java)
- ‘Switch’ Workspace – then Switch back (Eg Change to Debug, then switch back to Java)
- Remove and re-add your JRE:
1. Right Click on your project > properties
2. Click on the Libraries tab
3. Click on the JRE
4. Click remove, then OK
5. Repeat 1-3 again, but add the JRE again
Hope at least ONE of those tips help!
Thanks cleaning worked..:)
Thanks a lot, “clean” worked great, good to see someone publish proper hands on tips !
Thank You
Hi All,
I tried everything mentioned above; everything from clean to refresh to switch.
I am getting the error :
Exception in thread “main” java.lang.Error: Unresolved compilation problems:
The import com.sun.net.ssl.internal.ssl.Debug cannot be resolved
Debug cannot be resolved
Debug cannot be resolved
Debug cannot be resolved
——————————————-
I think the trouble is with jre version , at this error I had jre1.7, and when I used 1.5 this error was gone but a new error for Javax.swing was introduced. Almost wasted two days on it.
If anybody can help, it would be appreciated.
Thank you!!! … It really helped me too…I am using RAD. I cleaned the project many times but it did not solve the issue. I disabled the option – Build Atomatically’ and then cleaned the project and did a manual build. The problem solved.
Thanks so much! Really saved my time!!!
Worked like a charm, thanks!
First option/choice worked in my case….
Thanks a lot..
First option/choice of cleaning the project worked in my case….
Thanks a lot..
I get to be crazy, i have downloaded also the last versione (Indigo) but the problem still exists. i’ve tried all off tricks in this post without any solution.
Hey.. great tips, Cleaning fixed my problems!!!
Thanks for the tips. Apparently I didn’t clean my project after re-importing it from another IDE.
Oh! Thanks man! I’ve waste 2 hours dancing around build paths…
Same as most here…
‘Clean’ is the one.
Won’t forget that any time soon!
Thanks clean worked
thanks, that was halepfull
Thanks! I completely forgot about this step and almost wasted an hour trying to fix my project dependencies.
Restarting Eclipse worked for me. Weird.
This worked for me:
Remove external libraries/jar and add them again.
Cleaning project helped me from deleting and again building the project setup that would take 30 mins. At times even deleting didnt help. This is indeed a simple solution.
It would be good if you can mention the reason why we face this problem. All of a sudden when we are editing file, it shows up with red. Very wierd and disgusting at times.
Thanks, the first tip did the trick.
Can be caused when the artifact item version of the related projects vary.
This may work for some time and this error pops up when we try to access some of the newly added functions in that artifact.
This is a probable cause there can be many more…
Or you can just compile with errors.
When this happens to me, its frustrating, but I just ignore it until I do enough stuff in the IDE so that it fixes itself.
[...] Thank you Sherif Mansour. [...]
Thanks..! I spended lot of time with this error
One of the reasons is, make sure all the source code is in the src directory. If it is not, then add those non-standard source directories to the build path.
Another common reason is that you most likely not provided the path(s) to all the external jars that your application is referencing.
thx, it solved my pblm.
fought with trying to add/remove classes and wasted my time
Cleaning wouldn’t help, though I thought that the fact that I’m using Git to sync between two computers was the issue.
Nope, ended up making a package and putting my stuff into it… Guess I should start doing that on the regular from now on, huh?
Thanks. Turns out my JRE spec was goosed. Found your page after 1/2 a day of fooling around, got down to JRE switching, checked the JRE spec, corrected it and I’m good to go.
Thanks!
Thanks, the following steps worked for me:
- ‘Clean’ Your Eclipse Project: Go to Project > Clean in Eclipse [This seems to work for me]
- Refresh your project folder (right click on your project > refresh)
- Re-build your project
[...] a look at this post and this. It will resolve your [...]
O thank u sooo much i was trying so hard and after doing this i came to know that problem was not in my code it was actually in my ecplise
Thank You
Thank you,
The problem was really bothering me.
First solution:
- ‘Clean’ Your Eclipse Project: Go to Project > Clean…
worked instantly!
Switch workspace and switch it back, after that clean and build.. Works like charms!! Thanks!!
Thanks a lot
needed to leave a comment for showing my gratitude that you saved me a great deal of time
Cleaning project was worked for me, but after I re-build the project, the error appear again. Help.
i added hibernate jars properly but still i am getting this problem that is” The import org.hibernate.Session cannot be resolved” how to solve this problem??….
Thanks a lot!