公共类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]);
}
}
}
嗨大家我在尝试NullPointException
和tempReading.setText()
时得到errorReading.setText()
。我在fxml文件中定义了标签文本的默认值。
答案 0 :(得分:1)
似乎tempReading
和errorReading
都为空。
也许绑定到FXML是不正确的?
确保FXML文件中的fx:id
与Java类中的Label字段的名称相匹配。