如何从Eclipse导入包? [英] How to import a package from Eclipse?
问题描述
在我的一个目录中,我拥有属于一个包(游戏)的所有.java文件。现在我想创建一个不属于这个包并导入游戏包的.java文件。如果我创建一个新文件并编写导入游戏;
那么Eclipse会抱怨它不知道游戏包的含义。有人可以帮我解决这个问题吗?
In one of my directories I have all .java files which belong to one package ("game"). Now I want to create one .java file which does not belong to this package and which imports the "game" package. If I create a new file and write import game;
then Eclipse complains that it does not know what the "game" package means. Can somebody please help me to solve this problem?
推荐答案
您无法导入包,需要从该包导入类:
You cannot import a package, you need to import classes from that package:
import game.SomeClass;
import game.SomeOtherClass;
或
import game.*;
从该包中导入所有类。
如果在代码中键入类名,Eclipse可以为您生成这些导入,并按 Ctrl + Space 进行代码完成。在那里选择正确的类(如果不同的包中存在更多具有相同名称的类),则将生成导入。
Eclipse can generate these imports for you if you type the class-names in your code and press Ctrl+Space for Code-Completion. Select the correct class there (if more classes with the same name exist in different packages), and the import will be generated.
这篇关于如何从Eclipse导入包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!