我嘗試綁定一個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 ... –