我已經創建了一個與telnet協同工作的聊天服務器。現在,我正在嘗試寫我自己的客戶。我需要能夠從用戶和端口號獲取IP地址。我試圖通過ChatClient()傳遞這些變量。然而,當我編譯下面的代碼,我收到以下錯誤信息:Java聊天客戶端連接服務器
ChatClient.java:24: cannot find symbol
symbol : variable ip
location: class ChatClient
new ChatClient(ip,port);
^
ChatClient.java:24: cannot find symbol
symbol : variable port
location: class ChatClient
new ChatClient(ip,port);
^
2 errors
ChatClient.java
public class ChatClient {
PrintWriter output;
BufferedReader input;
Socket client;
public ChatClient(int ip, int port) throws Exception {
String line;
input = new BufferedReader(new InputStreamReader(client.getInputStream())) ;
output = new PrintWriter(client.getOutputStream(),true);
output.println("Enter an ip address: ");
line = input.readLine();
output.println("Enter a port number: ");
line = input.readLine();
}
public static void main(String ... args) {
try {
new ChatClient(ip,port);
} catch(Exception ex) {
out.println("Error --> " + ex.getMessage());
}
} // end of main
}
做一個清理並重新編譯 – Adrian 2012-01-31 16:37:09
在main方法的範圍內沒有ip或port變量。 – qrtt1 2012-01-31 16:37:19