我为套接字创建了一个自定义类:
class clientSocket{
Socket clientSocket = null;
public clientSocket() {
}
void accept(ServerSocket welcomeSocket) throws IOException{
clientSocket = welcomeSocket.accept();
}
}
当我尝试在如下所示的服务器类中使用它时,它将引发空指针异常:
ServerSocket sSocket = new ServerSocket(1234);
clientSocket[] client = new clientSocket[3];
client[0].accept(sSocket); //this throws a null pointer exception.
你知道为什么第三行会抛出空指针吗?