Eclipse中导入类的问题

发布于 2024-12-05 14:35:52 字数 540 浏览 0 评论 0原文

我有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

彡翼 2024-12-12 14:35:52

如果您有两个 Eclipse 项目,它应该类似于:

[Project ch6]
  -java
  -Build Path
   ....
[Project game]
  -java
  -Build Path
  ...

要导入您想要的跨项目 -> (您可以通过多种方式到达该路径)

  [right click] ch6 -> Properties -> Build Path  
  Projects Tab -> Check [game] || (add) Project [game];

然后进行干净的构建。这应该可以解决导入问题并合并路径。

编辑:根据埃德的建议颠倒了顺序。

If you have two Eclipse projects it should look something like:

[Project ch6]
  -java
  -Build Path
   ....
[Project game]
  -java
  -Build Path
  ...

To import cross project you want -> (you can get to the path a number of ways)

  [right click] ch6 -> Properties -> Build Path  
  Projects Tab -> Check [game] || (add) Project [game];

Then do a clean build. That should resolve the import and combine the paths.

edit: reversed the order per Ed's suggestion.

尛丟丟 2024-12-12 14:35:52

我想如果您没有使用正确的目录结构,您可能会看到这一点 - 如果 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文