我尝试绑定一个String
和StringPoperty
,我认为这会工作:空指针试图绑定一个stringproperty
@FXML private TextArea consoleTextArea;
StringProperty sp = new SimpleStringProperty();
consoleTextArea.textProperty().bind(sp);
但是这回我一个NULL Pointer Exception
,为什么呢?
编辑:一些答案后,似乎我consoleTextArea
是NULL
,但我正确初始化: <TextArea id="consoleTextArea" fx:id="consoleTextArea" prefHeight="309.0" prefWidth="600.0" VBox.vgrow="ALWAYS" />
,并我调用控制器之前创建的窗口,所以我不undertand为什么会NULL
...
最有可能的文本区没有被fxml加载器初始化。你可能会wonna仔细检查,如果你使用的文本区域的名称是正确的FXML-文件中拼写为好,或者你试图将值绑定时,FXML装载机甚至被称为前。但是如果没有代码,我们只能猜测那里真的发生了什么。 – crusam
我确实consoleTextAea,似乎空,但我之前装入FXML ... –