I am a beginner with JavaFX and I have a problem when I click the button, I am trying to setText() to TextArea from String. But, I got an error. This is my code:
@FXML
private TextArea chat1, chat2; //text area show message
//in ActionEvent method of button
String s = this.message2.getText();
chat1.setText(Chat2.username2 + ": " + s);
Cannot invoke "javafx.scene.control.TextArea.setText(String)" because "this.chat1" is null
chat1
is null. Obviously no-one can tell you why it's null from the code you have posted. - James_Dchat1
an ID in that .fxml file? Your use of bothchat2
andChat2
in your question leads me to wonder if you aren’t paying attention to case in both places. - VGR