Wednesday, January 21, 2015

Eclipse : The import .... cannot be resolved



Question :

I use Eclipse and turns out I have a bunch of import * not resolved errors.
 
 
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
All of the above have the same error. I checked my java version it is 1.7.0 open jdk. I updated Java Home and the JRE library to use. Its still not working. Note: I imported the code repository from bibucket via the mercurial plugin itself.

Answers: 

Did you check the installed JREs in your eclipse. Path is windows preferences - > java -> installed JREs ....as below in detail.

Right click on project - >BuildPath - >Configure BuildPath - >Libraries tab - >
Double click on JRE SYSTEM LIBRARY - >Then select alternate JRE

 -----------------------------------------------------------------------------------------------------
If the project is Maven, you can try this way :
  1. right click the "Maven Dependencies"-->"Build Path"-->"Remove from the build path";
  2. right click the project ,navigate to "Maven"--->"Update project....";
Then the import issue should be solved .

------------------------------------------------------------------------------------------------------Try cleaning your project by going to the following menu item:
Project > Clean

If that doesn't work, try removing the jars from the build path and adding them again.

------------------------------------------------------------------------------------------------------
Clean the project. And double-check the jars being really on the build path (with no errors). Also make sure there is nothing in the "Problems" view.

----------------------------------------------------------------------------------------------------------

 I found the problem. It was the hibernate3.jar. I don't know why it was not well extracted from the .zip, maybe corrupt. A good way to check if jars are corrupt or not is navigating through their tree structure in "Project Explorer" in Eclipse: if you can't expand a jar node probably it's corrupt. I've seen that having corrupt packages it's frequent when you drag and drop them to the "Project Explorer". Maybe it's better to move and copy them in the OS environment! Thankyou all.

--------------------------------------------------------------------------------------------------------------

I  had the problem, that the classpath was broken somehow.
So right click on the project in Package explorer > Plug-in tools > Update classpath... did it for me
---------------------------------------------------------------------------------------------------------------

I  had the same problem because I added a jar I created, where I had set the packaging base directory other than the base directory of the classes. As a result the class e.g. java.util.List had to be imported as util.List although the suggested import was the first one.
Check the imported jars under referenced libraries to see that they are imported correctly

-----------------------------------------------------------------------------------------------------------

I  got the same problem. I downloaded the jar and added it to the build path, but I didn't notice that the extension was .jar.zip. I again converted it to .jar and added to the build path.
It solved my problem. It's a very silly mistake but I wrote it here in case it could help someone.
-----------------------------------------------------------------------------------------------------------------



 


No comments:

Post a Comment