开发者

compile error: The import xxxx cannot be resolved

I am developing a Java project using Eclipse. The project uses another project called engine, which I have added in my project build-path. As I need to call a dabo class, called House, in one of my project class, named Window, I have used the following code as usual:

import ee.asus.kernel.House;

I got however the following error in compiling time:

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
The import ee cannot be resolved
House cannot be resolved to a type
House cannot be resolved to a type
House cannot be resolved to a type

at main.ee.asus.GUI.FrameWindow.Window.<init>(Window.java:10)开发者_C百科
at main.ee.asus.GUI.StartApplication.main(StartApplication.java:13)

It's worth to point out that my prject and the dabo project use the same directory/packages names. Does anyone have a clue where the error may be?


The error can't resolve the first part of the package name: ee. Are you sure the package starts with ee? I see your Window class package starts with main.ee, does your engine project start with the same package structure?


I sometimes get weird behaviour with missing class files etc. when Eclipse is out of sync with the filesystem.

You could try refreshing all of your projects and doing a full rebuild.


I have been experiencing the same problem. I have an app A1(tablet version app) calling another app A2(phone version app). Upon calling, I see the same error message:

java.lang.Error: Unresolved compilation problems: 
The import xxxxx cannot be resolved
xxxx cannot be resolved to a type
xxxx cannot be resolved to a type
xxxx cannot be resolved to a type

After poking around for a while, I realized the problem was the A2 doesn't run on tablet at all. It's weird because the immediate previous version of A2 runs perfectly on the same tablet(I have been on board only for 1 month). So I decided there was something wrong in the build config.

Finally, I fixed the problem by changing the order of Java Build Path. Although I have no idea why it worked, hopefully this will shed some light on your problem.


Look for the House class in your second project, opens it and see what package it is in.
(line "package xxx.yyy.zzz;" at the beginning of the House.java file)

Then make sure your Window.java file (class main.ee.asus.GUI.FrameWindow.Window) does have the line "import xxx.yyy.zzz.House;" in it.


In my case it was a version conflict.

I'm using maven and updated many packages and bumped versions of many projects. Maybe the reactor built mixed something up, or the transitive dependencies weren't up-to-date, or it was a change in a project without a version increment. However, rebuilding that project explicitly via maven fixed the problem.

Edit: When I think about it, it might also have been a conflict between eclipse's auto-build and building via maven on the command line.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜