2014-01-13 88 views
1

我有控制器來處理由場景生成器創建的UI的動作。 現在,當我試圖從這個UI綁定到Controllers構造函數中的SimpleTextProperty時,我得到了nullpointer異常。顯然productInfoLabel還沒有實例化。我應該在哪裏綁定這些而不是構造函數? 這裏是我的代碼如何正確綁定javafx標籤(從fxml)到SimpleStringProperty

public class Controller { 
    @FXML 
    public TableView receiptTable; 
    @FXML 
    public TextField productCodeTextField; 
    @FXML 
    public Label productInfoLabel; 
    private StringProperty stringProperty = new SimpleStringProperty(); 

    public Controller() { 
    productInfoLabel.textProperty().bind(stringProperty); 
    } 
} 

所以我的問題是如何正確地做到這一點?

+3

好吧,我已經得到它。控制器需要實現可初始化的接口 – sw1

回答