DatagramSocket
沁海棠 2017-02-21 01:01:54 把DatagarmSocket做为类属性并直接构造,为什么会报错。求解,Default constructor cannot handle exception type SocketException thrown by implicit super constructor. Must define an explicit constructor
写在方法里面就可以了。
public class Server {
DatagramSocket serber = new DatagramSocket(6666);
}
public class Server {
public void reception(){
try {
DatagramSocket server = new DatagramSocket(6666);
} catch (SocketException e) {
e.printStackTrace();
}
}
}
求详解