本帖最后由 郑世光 于 2012-10-10 13:35 编辑
下面的代码只有DatagramSocket datareceive=new DatagramSocket(10009);和 DatagramSocket datasend=new DatagramSocket(); 抛异常,但是只将这2句话进行try处理的话,下面的datareceive和datasend都提示没有初始化,好像他们的作用域只在try块中了!这是为什么?
public static void main(String[] args) {
DatagramSocket datareceive;
DatagramSocket datasend;
try {
datareceive = new DatagramSocket(10009);
datasend = new DatagramSocket();
} catch (SocketException e) {
e.printStackTrace();
}
Send send=new Send(datasend);// The local variable datasend may not have been initialized
Receive rece=new Receive(datareceive);//The local variable datasend may not have been initialized 可是上面在try中已经创建了啊
Thread t1=new Thread(send);
Thread t2=new Thread(rece);
t1.start();
t2.start();
} |