Eclipse中导入类的问题
我有 2 个包,每个包都在不同的项目中,一个包称为 ch6,其中包含类 X,另一个包是游戏,其中包含类 Gamer,当尝试在 XI 中手动导入 game.Gamer 时,出现错误:“无法解析导入游戏” ”,但是当我将鼠标悬停在错误的红线上并选择“修复项目设置..”时,会出现一个对话框,要求将类游戏的项目导入到X的项目路径中,并且问题已修复,为什么不能我添加手动 game.Gamer 尽管我使用相同的语法?
* 编辑*
根据要求包括代码:
项目 ch6:
package ch6;
abstract public class X {
private int x = 7;
public static final int y = 24;
}
项目 HFJ:
package game;
public class Gamer {
public int z;
}
I have 2 packages each in a different project , one package is called ch6 which includes class X , the other package is game which includes class Gamer , when trying to import game.Gamer manually in X I get error : "The import game cannot be resolved " , but when I hover on the red line of the error and choose "fix project setup.." , a dialog box appears offering importing the project of class game to the path of project of X and things are fixed, why can't I add the game.Gamer manually although I use the same syntax ?
* EDIT *
Including code as requested:
project ch6:
package ch6;
abstract public class X {
private int x = 7;
public static final int y = 24;
}
project HFJ:
package game;
public class Gamer {
public int z;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您有两个 Eclipse 项目,它应该类似于:
要导入您想要的跨项目 -> (您可以通过多种方式到达该路径)
然后进行干净的构建。这应该可以解决导入问题并合并路径。
编辑:根据埃德的建议颠倒了顺序。
If you have two Eclipse projects it should look something like:
To import cross project you want -> (you can get to the path a number of ways)
Then do a clean build. That should resolve the import and combine the paths.
edit: reversed the order per Ed's suggestion.
我想如果您没有使用正确的目录结构,您可能会看到这一点 - 如果 game.Gamer.java 没有存储为 /game/Gamer.java。
另外,如果您还没有尝试刷新项目(在树中选择项目,然后选择菜单“文件..刷新”)。
I think you might see this if you didn't use the correct directory structure - if game.Gamer.java wasn't stored as /game/Gamer.java.
Also, if you haven't already, try refreshing the project (select the project in the tree, then menu File..Refresh.