我的目录结构如下所示:
sudo /opt/bitnami/ctlscript.sh start
运行文件StudentClient.java时出现错误,该文件包含StudentAddress类的实例。服务器已成功启动,但客户端无法正常工作。
源代码:-
ObjectPassing
|->student.txt
|->StudentAddress.java
|->StudentClient.java
|->StudentServer.java
|->StudentAddress.class
|->StudentClient.class
|->StudentServer.class
所有类StudentAddress,StudentServer,StudentClient均已成功编译。在运行StudentClient.java时,显示以下错误:
命令:javac StudentClient.java
import java.net.Socket;
import java.io.ObjectOutputStream;
public class StudentClient{
private String hostName;
private int portNumber;
private Socket client;
public StudentClient(String th,int tp){
this.hostName = th;
this.portNumber = tp;
try {
client = new Socket(hostName,portNumber);
ObjectOutputStream output = new ObjectOutputStream(client.getOutputStream());
StudentAddress data = new StudentAddress();
data.getData();
output.writeObject(data);
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
new StudentClient("localhost",8000);
}
}
答案 0 :(得分:0)
哦,等等,您正在Enum
目录中运行javac,这就是问题所在。
从ObjectPassing
目录运行它。
当您提及Networking
关键字时,package
将在当前目录下运行的目录中包含该软件包名称的目录。