i'm getting a return NullPointerException when i try to create a socket connection, when i try to print socket.isConnected()
on the main class it return true, but when i try to print it again on the other method, it return NullPointerException, here is my code.
Server
ServerSocket socketServer = null;
Socket socketConnect = null;
public static void main(String[] args) throws IOException {
ChatServer cc = new ChatServer();
cc.socketServer = new ServerSocket(2000);
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ChatServer().setVisible(true);
}
});
cc.socketConnect = cc.socketServer.accept();
System.out.println(cc.socketConnect.isConnected());
}
public void send(String msg) throws IOException {
System.out.println(this.socketConnect.isConnected());
}
this code will return true first, because the socket.isConnected() is working on the main, but not on the send method