I am writing/reading from serial port with my java fx application. All is fine until I read the data from port. Once I received the data I pass it to the method thats located in my controller for processing. After passing the data to the method in controller I am trying to assign it into my textboxes but it throws NPE exception. I even tried with Platform.runLater() but still gives me the same NPE message. Any help please?
//Serial data reader
@Override
public void serialEvent(SerialPortEvent event) {
if (event.getEventType() != SerialPort.LISTENING_EVENT_DATA_RECEIVED)
return;
packet = event.getReceivedData();
// Also tried this myController.processData(packet); Still NPE
Platform.runLater(()->
{
settingsController.processData(packet);
});
}
//The method in myController
@FXML
private JFXTextField dataTextField;
public void processData(int[] packet) {
dataTextField.textProperty().setValue(String.valueOf(packet[2])); //Here it throws NPE due to dataTextField
//dataTextField.textProperty().setValue(String.valueOf(5)); Also tried a dummy value to find out if it is text field or the packet data. I confirmed it is NPE of dataTextField
//I also tried this .Still the NPE. Also tried with combobox. so no hope
Platform.runLater(()->
{
dataTextField.textProperty().setValue(String.valueOf(packet[2]));
});
}