更改javafx

时间:2018-04-03 09:19:26

标签: java

公共类SerialCommunicationController {

    @FXML public Label tempReading;
    @FXML public Label errorReading;

    private final Logger logger = LoggerFactory.getLogger(getClass());
    private ArduinoInterfaceControl arduinoInterfaceControl;
    private Stage stage;
    private String prop;
    private String inte;
    private String deri;
    private boolean lastCommandSuccessful;
    public static final String LOCAL_SIMULATOR = "Local Simulator";
    private String[] params;
    private ArduinoInterfaceControl arduinoInterface;
    public SerialCommunicationController() {
    }
    public SerialCommunicationController(String cmd){
        setValues(cmd);
    }

    public void setValues(String readings){
        String[] params = readings.split("\\s+");
        // something went wrong, just decode to blank.
        if(params.length < 1) {
            lastCommandSuccessful = false;
        }
        else {
            tempReading.setText(params[0]);
            errorReading.setText(params[1]);
            // successful command received.
            lastCommandSuccessful = Boolean.valueOf(params[1]);
        }
    }

}

嗨大家我在尝试NullPointExceptiontempReading.setText()时得到errorReading.setText()。我在fxml文件中定义了标签文本的默认值。

1 个答案:

答案 0 :(得分:1)

似乎tempReadingerrorReading都为空。 也许绑定到FXML是不正确的?

确保FXML文件中的fx:id与Java类中的Label字段的名称相匹配。