I am getting "Exception in thread "Thread-2" java.lang.NullPointerException at client.Client.run(Client.java:32)" line 32 is the switch statement line below. The switch is on a enum method. I think the error is a from one of the threads going faster than the other but i'm unsure... I hope i've provided enough code here if not I will add more let me know what I need to add.
public void run() {
while (running) {
try {
switch (receiveMessage()) {
case SERVER_HELLO:
expectingServerHello = true;
break;
//other cases
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
public ServerMessages receiveMessage() throws IOException {
String sentence;
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
sentence = inFromServer.readLine();
return MessageSerialize.fromServerMessage(sentence);
}