找不到类???

nuaacpc 2011-06-05 10:40:47
package javaworks.net.multicast;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
public class MChatServer
{
public static final String GROUP_IP="230.0.0.1";
public static final int MAX_PACKET_SIZE=65507;
public static final int SERVER_PORT=2008;
public static void main(String args[])throws IOException
{
System.out.println("==========UDP cast=========");
try
{
MulticastSocket server= new MulticastSocket(SERVER_PORT);
InetAddress group= new InetAddress.getByName(GROUP_IP); server.joinGroup(group);
System.out.println("now listenning"+server.getLocalPort()+"...");
while(true)
{
try
{

byte buffer[]=new byte[MAX_PACKET_SIZE];
DatagramPacket packet=new DatagramPacket(buffer,buffer.length);
server.receive(packet);
String s=new String(packet.getData(),0,packet.getLength());
System.out.println(""+packet.getAddress().getHostAddress()+":"+packet.getPort()+":"+s);
if("shutdown".equals(s))
break;
}
catch(Exception e)
{
e.printStackTrace();
}
}
server.leaveGroup(group);
server.close();

}
catch(Exception e)
{
e.printStackTrace();
}
}
}

运行结果:
cannot find symbol class getByname
怎么回事?这还是书上的例子。。。。
...全文
162 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
alinchuan 2011-06-06
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 tkd03072010 的回复:]
静态的方法 直接调用 不用new
[/Quote]
很简单的错误,lz 自己要多学会解决这样不起眼的小错误
chenchenyangll 2011-06-06
  • 打赏
  • 举报
回复
1L已经说明所有问题了
TKD03072010 2011-06-05
  • 打赏
  • 举报
回复
静态的方法 直接调用 不用new
riyuezhizhi 2011-06-05
  • 打赏
  • 举报
回复
同意LS说法
JavaMan 2011-06-05
  • 打赏
  • 举报
回复
InetAddress group= new InetAddress.getByName(GROUP_IP);
这种写法错误,不用new,
悠忧虫 2011-06-05
  • 打赏
  • 举报
回复
new InetAddress.getByName(GROUP_IP);

getByName是静态方法,把new去掉

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧