Java 套接字上的空指针异常
在下面的代码中,我得到一个空指针异常(在标记行)。第一个方法(join)调用thread-joinThread来运行与主机过程的连接Java 套接字上的空指针异常,java,Java,在下面的代码中,我得到一个空指针异常(在标记行)。第一个方法(join)调用thread-joinThread来运行与主机过程的连接 public void join () { try { socket = new Socket (address, 3150); //address received elsewhere BufferedReader i
public void join () {
try {
socket = new Socket (address, 3150); //address received elsewhere
BufferedReader in = new BufferedReader (new InputStreamReader (socket.getInputStream ()));
PrintWriter out = new PrintWriter (socket.getOutputStream (), true);
joinThread jointhread = new joinThread (this);
out.write (user.getText ());
jointhread.start ();
} catch (IOException e) {
}
});
public class joinThread extends Thread {
MainScreenController controller;
public joinThread (MainScreenController controller) {
this.controller = controller;
}
@Override
public void run () {
Socket socket = null;
FXMLLoader fxmlLoader = new FXMLLoader ();
String inRead =null ;
try {
////////////////////////////////NPE
while (inRead==null) inRead = controller.in.readLine (); // Elsewhere a String will be sent
//to thissocket
////////////////////////////////NPE
} catch (IOException e) {
e.printStackTrace ();
}
TIA
已解决,在主类中未初始化(仅在联接方法中)