Eclipse error: “The import XXX cannot be resolved”

安稳与你 提交于 2019-11-26 11:14:51

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.

Obviously there are cases where there is a valid issue however Eclipse throws this error for no good reason sometimes.

This still (2019-03) is an old (2010) Eclipse bug that can be resolved by making a negligible change to the project settings.

The setting I chose to change was: Project > Properties > Java Build Path > Order and Export > make a meaningless order change > Apply.

Changing the order back does not regress to the problem. Simply touching the file might also resolve the issue (I'll test touch next time).

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.

If is a Maven project, also click on Maven >> Update project... (F5)

wuppi

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

SoldierShen

I solved it by removing the project (do not delete on the disk) and importing it again.

  1. clean project Project - > clean...
  2. Right click on project - >BuildPath - >Configure BuildPath - >Libraries tab - >

Double click on JRE SYSTEM LIBRARY - >Then select alternate JRE

Try adding JRE System Library in the build path of your project.

Alex P.

With me it helped changing the compiler compliance level. For unknown reasons it was set to 1.6 and I changed it to 1.8.

Once at project level right click on project > Properties > Java Compiler, while in Eclipse click on menu Window > Preferences > Java > Compiler.

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 didn't understand the reasoning behind this but this solved the same problem I was facing. You may require these steps before executing steps mentioned in above solutions (Clean all projects and Build automatically).

right click project -> Properties -> Project Facets -> select Java -> Apply

Srinivas Thammanaboina

Whenever you come across this problem just go to Project > Clean, then select Clean all projects. It should get resolved, otherwise try to delete those jars and add them again. Last thing would be to try restarting Eclipse.

I tried all of the answers above but no luck. In my case, there is a generated build/classes folder with some additional ".class" files. I ended up going to the package explorer, right-clicking on the project and selecting the "Refresh" option and that made the build/classes folder available again resolving the issue.

Atul Waghmare

This has solved my issue.

1) clean project Project -> clean...

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

3) Click Save

4) Again go to your project in project explorer and right click to project -> BuildPath -> Configure BuildPath -> Libraries tab -> Double click on JRE SYSTEM LIBRARY -> This time select "Execution Environment"

5) Apply

Evgeny Shmulev

In my case it was a broken jar in the Maven repository. Delete jar files in repository and let Maven download them again.

When I ran mvn clean install from the command line, it ran fine, but Eclipse still could not compile the code. When I ran maven install in Eclipse then I saw that Maven complained about bad jar file. So I deleted it and ran maven install again. The problem was gone.

ÖMER TAŞCI

In order to download non-existing jar file in your .m2 directory, you should run mvn clean install command for your project pom.xml. Then you should update the project dependencies by clicking Alt+F5. This works for me!

Ravikumar

Please try and check whether all the libs are in place. I had the same issue. But I solved it by moving the lib folder and adding all the jars again in the build path.

Ali786

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.

If you are working with Maven and have this problem, check the repository server (for example nexus server), if the artifact is there. Sometimes, they can change the name of the artifact and you try to get the artifact with its old name.

Resolved by linking the source. From the explorer right click on the project, select properties, select Java Build Path, select Source from tabs, press button "LinkSource". And specifying the folder to add to the project.

I couldn't import as well. Took me some hours to figure out, that I tried to use a 1.6 bound library/jar, while I was trying to compile for 1.8. When I switched my project also to use 1.6, the import issue has gone. All error messages were leading into wrong directions. Just in the source I found some limitations directing to 1.6 version. And: For example the .settings and .classpath (File-Search) -> org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 can give a hint, on such issues.

I faced the same issue and I solved it by removing a jar which was added twice in two different dependencies on my pom.xml. Removing one of the dependency solved the issue.

Removing the "module-info.java" did resolve the issue for me!

This file was automatically generated and did appear in my hierarchy...

Kalahasthi Satyanarayana

I resolved this issue by updating the project: right click on the Maven project, select Maven -> Update Project -> select checkbox Force Updates of Snapshots/Releases.

Leandro Bonini

I solved this problem using the JPA JAR from Maven repository, adding it on the build path of project.

For me,

Project ---> Source ---> Format

solved the problem

If you're developing plugins in eclipse and you're using a target platform (which was my case) you need to make sure you check the target's platform configuration from Window->Preferences->Plug-in Development->Target Platform and make sure your target platform is checked and configured. Hope this helps.

Check If Your POM file is Updated with same Version in all Modules.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!