I'm trying to open a thread in Java, but for some reason I get an exception every time. my syntax :
Thread receiveThread2;
receiveThread2 = new Thread(() -> {
try {
receiveMessageNoLoop();
}
catch (IOException ex) {
Logger.getLogger(ModelClient.class.getName()).log(Level.SEVERE, null, ex);
}
});
receiveThread2.start();
My function receiveMessageNOLoop()
is in the same Java class:
public void receiveMessageNoLoop() throws IOException {
String stringData;
inFromServer.read(dataForLoop2, 0, 1024);
takeCareOfJason(dataForLoop2);
}
If I do that without a thread, it works perfectly. problem is, I must use thread and for some reason it gives me nullPointerException.