小問題,自已搞不定!(50分)

  • 主题发起人 主题发起人 悟峰
  • 开始时间 开始时间

悟峰

Unregistered / Unconfirmed
GUEST, unregistred user!
JCreator編輯,代碼如下:
import java.io.*;
import java.net.*;
public class Client
{
public static void main(String[] args)
{
int port=8000;
String inString;
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);

try
{
InetAddress address=new InetAddress.getByName(null);
Socket socket=new Socket(address,port);
OutputStream os=socket.getOutputStream();
OutputStreamWriter osw=new OutputStreamWriter(os);
PrintWriter pw=new PrintWriter(osw);
while ((inString=br.readLine())!=null)
{
pw.println(inString);
pw.flush();
if (inString.trim().equals("quit"))
System.exit(0);
}
}
catch (IOException e)
{
System.err.println(e);
}
}
}
編寫的Server則正常,何故提示信息如下:
--------------------Configuration: Client - JDK version 1.3.1_04 <Default>--------------------
C:/Program Files/Xinox Software/JCreator Pro/MyProjects/Helloworld3/variableclass/customer/cathcdemo/labeldemo/labeldemo/uselistenerdemo/hello/Client/Client.java:27: cannot resolve symbol
symbol : class getByName
location: class java.net.InetAddress
InetAddress address=new InetAddress.getByName(null);
^
1 error
Process completed.
按道理說,getByName()應該在java.net.*這個包里面啊?
 
jdk里帮助里说明了
static InetAddress getByName(String host)
Determines the IP address of a host, given the host's name.
--------
getByName是静态方法 所以你把
InetAddress address=new InetAddress.getByName(null);
改为
InetAddress address = InetAddress.getByName(null);
就对了
 
結貼,謝謝7syw,交個朋友,qq:54540657
 
没有QQ
7syw@163.com
 
后退
顶部