Error thread in the application tab.getId().equals(). Someone tell me what's the problem?

Who will help help to understand what the problem is. Method code and error below.
public void getMessage(Response response) {
 String id = response.getFrom();
 for (int i = 0; i < tabPane.getTabs().size(); i++) {
System.out.println(tabPane.getTabs().get(i).getId());
 Tab tab = tabPane.getTabs().get(i);
 if (tab.getId().equals(id)) {
 VBox vBox = (VBox) tabPane.getTabs().get(i).getContent();
 TextArea textArea = (TextArea) vBox.getChildren().get(0);
 textArea.appendText(response.getFrom() + ": "+ response.getMessage());
break;
}
}
 }


Exception in thread "Thread-4" java.lang.NullPointerException
at chat.client.view.ChatController.getMessage(ChatController.java:98)(It is a string if (tab.getId().equals(id)) )
at chat.client.MainApp.onReceiveString(MainApp.java:124)
at chat.client.network.TCPConnection$1.run(TCPConnection.java:37)
at java.lang.Thread.run(of the Thread.java:748)
June 5th 19 at 21:28
1 answer
June 5th 19 at 21:30
Solution
1) annoying "Exception in thread "Thread-4" java.lang.NullPointerException", not an hour of another thread if everything works?
2) I assume that (Response response) flies from another thread? Not the case, wipe to the time of the inspection String id?
3) similarly, if there Tab tab = tabPane.getTabs().get(i)?

Recommendations
- the, here's the MOST important, any operations ui performed ONLY in the flow of javafx.
just tab.getId() does not cause npe? Just in case, read how a better look at the source\the docks, it is possible that if id is not set it will return null and not equals null and hence npe.
-take up a debugger, put breakpoint to the line step by step and see what that variable is.
very critical moment, don't do porridge in the form of reception-processing-drawing in one place, it just creates problems with the threads. Tip, take the collection which can mnogovato, for example a network flow received the package and threw it into the collection and then works on, from this collection the 2nd thread took the bag and handles, and the result is ,for example, responds back to the client or sends the processed data to another collection from which the data will pick up the flow and will draw javafxui. Ie network stream received and put into the collection without thinking at all that there is, why and where. Stream benelogic already digested these data and decides what and how much, the ui thread does actually nothing and only draws new data.

Actually Wang that messed up the flow and hence such fun.
The whole mistake lay in the fact that in my tabPane does not have any elements, which yielded the null, something that I corrected and it worked.
I asked the question, as it gave an error only this operation:
tab.getId().equals(id)

tab.getId() worked, and here I was the issue, as tab.getId() worked, and tab.getId().equals(id) is already there.
But once again, the problem was that the tabPane I was empty.
But with the flow I like everything is normal, almost all as well implemented as you described.
Thanks for the reply and advice. Already taught me a lot. - Gretchen commented on June 5th 19 at 21:33

Find more questions by tags JavaJavaFX