Exception in thread "main" java.lang.NullPointerExceptionat

来源:百度知道 编辑:UC知道 时间:2024/05/28 06:18:00
Exception in thread "main" java.lang.NullPointerException
at xchat.XCHAT.main(XCHAT.java:91)

try{
socket = new JxtaServerSocket(myGroup,myUnicastPipeAdv,20);
socket.setSoTimeout(0);
}
catch(IOException e){
System.out.println("创建服务器套接字失败!!");
System.exit(-1);
}
try{
Thread.sleep(10000);
}
catch(Exception e){
}

while(true){
try{
JxtaSocket sock = (JxtaSocket)socket.accept();
if(sock==null)
System.out.println("sock is null...........") ;
System.out.println("sock :"+sock.toString()) ;
// InetAddress ia = sock.getInetAddress() ;
// System.out.println("ia :"+ia.toString()) ;

String sid =

很明显,你定义一个引用 A a=null
然后你直接使用a.f() A中的某个方法是f() 这样就会有这异常
也就是你的a未初始化,或者初始化失败

空指针异常,这是由于对象引用是null