i have a simple javafx FXML app that has a button and a textArea
I am trying to write to the textArea from another class (not the controller)
without sending the textArea to that class ,
i added a getter on my controller class, and on the writingClass i created an object of the ControllerClass
and then trying to write to the textArea , i am getting a java.lang.NullPointerException and java.lang.reflect.InvocationTargetException
what am i doing wrong ???
//Controller.java
package sample;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
public class Controller {
@FXML
Button myButton;
@FXML
TextArea myTextArea;
WriteToTextArea writeToTextArea;
public TextArea getMyTextArea() {
return myTextArea;
}
public void buttonPressed() {
writeToTextArea = new WriteToTextArea();
writeToTextArea.writeThis("trying To Write To TextArea");
}
}
//WriteToTextArea.java
package sample;
import javafx.scene.control.TextArea;
public class WriteToTextArea {
private Controller objectController;
private TextArea textArea;
public WriteToTextArea() {
objectController = new Controller();
textArea = new TextArea();
textArea = objectController.getMyTextArea();
}
public void writeThis(String whatToWrite) {
textArea.setText(whatToWrite);
}
}