Java cmd";“未找到类”;
我试图使用套接字将两台机器连接在一起,当我在cmd中键入java客户机时,我一直遇到这个错误。我设置了javac的路径 我导航到我的项目。我可以使用javac Client.java编译它,但不能使用java运行它。 请参见所附图片中的错误 我会附上客户的代码Java cmd";“未找到类”;,java,sockets,cmd,operating-system,Java,Sockets,Cmd,Operating System,我试图使用套接字将两台机器连接在一起,当我在cmd中键入java客户机时,我一直遇到这个错误。我设置了javac的路径 我导航到我的项目。我可以使用javac Client.java编译它,但不能使用java运行它。 请参见所附图片中的错误 我会附上客户的代码 public class Client { ObjectInputStream Sinput; // to read the socket ObjectOutputStream Soutput; // to
public class Client {
ObjectInputStream Sinput; // to read the socket
ObjectOutputStream Soutput; // towrite on the socket
Socket socket;
// Constructor connection receiving a socket number
Client(int port) {
// we use "localhost" as host name, the server is on the same machine
// but you can put the "real" server name or IP address
try {
socket = new Socket("192.168.43.115", port);
}
catch(Exception e) {
System.out.println("Error connectiong to server:" + e);
return;
}
System.out.println("Connection accepted " +
socket.getInetAddress() + ":" +
socket.getPort() + "\n");
/* Creating both Data Streams */
try
{
Sinput = new ObjectInputStream(socket.getInputStream());
Soutput = new ObjectOutputStream(socket.getOutputStream());
}
catch (IOException e) {
System.out.println("Exception creating new Input/output Streams: " + e);
return;
}
// my connection is established
String test = new String ();
test = "What is the date & time now ??";
// send the question (String) to the server
System.out.println("Client sending \"" + test + "\" to serveur\n");
try {
Soutput.writeObject(test);
Soutput.flush();
}
catch(IOException e) {
System.out.println("Error writting to the socket: " + e);
return;
}
// read back the answer from the server
String response;
try {
response = (String) Sinput.readObject();
System.out.println("Read back from server: " + response);
}
catch(Exception e) {
System.out.println("Problem reading back from server: " + e);
}
try{
Sinput.close();
Soutput.close();
}
catch(Exception e) {}
}
public static void main(String[] args) {
new Client(1500);
}
}
看看这个问题/答案
首先,您需要用“javac”将.java文件编译成.class文件,然后用“java”运行它。这里的问题是类
客户机
在包客户机
中。请确认。如果我没有放入clinet包,则表明编译时出错。。请参见图中可能的副本