简体   繁体   English

Eclipse中的导入类问题

[英]Import class problem in Eclipse

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 XI 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 ? 在尝试导入游戏时,我在不同的项目中分别有2个软件包,一个软件包称为ch6,其中包含类X,另一个软件包是包含类Gamer的游戏,在XI中手动进行游戏时出现错误:“导入游戏无法解析,但是当我将鼠标悬停在错误的红线上并选择“修复项目设置..”时,会出现一个对话框,提示您将类游戏的项目导入到X的项目路径中,并且事物已修复,为什么不能我使用相同的语法手动添加了game.Gamer?

* EDIT * *编辑*

Including code as requested: 根据要求包括代码:

project ch6: 项目ch6:

package ch6; 

abstract public class X {
    private int x = 7;
    public static final int y = 24;
} 

project HFJ: HFJ项目:

package game;

public class Gamer {
    public int z;
}

If you have two Eclipse projects it should look something like: 如果您有两个Eclipse项目,则其外观应类似于:

[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. 编辑:按照Ed的建议颠倒顺序。

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. 我认为如果您使用的目录结构不正确-如果game.Gamer.java未存储为/game/Gamer.java,您可能会看到此信息。

Also, if you haven't already, try refreshing the project (select the project in the tree, then menu File..Refresh. 另外,如果还没有刷新,请尝试刷新项目(在树中选择该项目,然后选择菜单File..Refresh。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM