[英]Compiling multiple files in Java using TextPad
I'm trying to compile my HelloApp2 file using TextPad, but it references another class in a different file in the greeter class. 我正在尝试使用TextPad编译我的HelloApp2文件,但它在greeter类的其他文件中引用了另一个类。 I keep getting errors that say that Greeter is not recognized. 我不断收到错误消息,说无法识别Greeter。 DOes anybody know how to do this in TextPad? 有人知道如何在TextPad中执行此操作吗?
HelloApp2.java: HelloApp2.java:
public class HelloApp2
{
public static void main(String[] args)
{
Greeter myGreeterObject = new Greeter();
myGreeterObject.sayHello();
}
}
Greeter.java: Greeter.java:
public class Greeter
{
public void sayHello()
{
System.out.println("Hello, World!");
}
}
If HelloApp2
references Greeter
, you need to put an import Greeter
into the top of HelloApp2.java
. 如果HelloApp2
引用了Greeter
,则需要将import Greeter
放入HelloApp2.java
的顶部。
import Greeter
public class HelloApp2
{
public static void main(String[] args)
{
Greeter myGreeterObject = new Greeter();
myGreeterObject.sayHello();
}
}
See the java docs about importing packages . 请参阅有关导入包的Java文档 。
This has nothing to do with TextPad... I would highly recommend using an IDE like Eclipse/NetBeans/IntelliJ Community Edition which are free and will save you loads of time writing, building, and debugging your Java software. 这与TextPad无关。我强烈建议您使用免费的IDE,例如Eclipse / NetBeans / IntelliJ Community Edition,这样可以节省编写,构建和调试Java软件的时间。
You need to import that class 您需要导入该类
import Greeter.*;
only if you have that file in the same folder where your main program is located 仅当该文件位于主程序所在的文件夹中时
or else you have to specify the package details like 否则您必须指定包裹详细信息,例如
import package.Greeter.*;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.