My program was working fine until i got this following message: "Exception in thread "Thread-0" java.lang.NullPointerException" in the run-method. It's pointing towards the row where i have written "Socket socket = serverSocket.accept();". Why is that and how can i solve it?
private ServerSocket serverSocket;
private LinkedList<ClientHandler> handlerList = new LinkedList<ClientHandler>();
private ArrayList<String> invalidUsernames = new ArrayList<String>();
public Server(int port) {
try {
serverSocket = new ServerSocket(port);
} catch (IOException e) {
e.getStackTrace();
}
start();
}
public void run() {
while (true) {
try {
Socket socket = serverSocket.accept();
ClientHandler handler = new ClientHandler(socket);
handler.start();
} catch (IOException e) {
}
}
}
public static void main(String[] args) {
new Server(6946);
System.out.println("Server started");
}
}