1

I've got Controller that handles actions from UI created by a Scene Builder. Now when i'm trying to bind a label from this UI to a SimpleTextProperty inside a Controllers constructor i'm getting nullpointer exception. Apparently productInfoLabel is not instantiated yet. Where should i bind these in instead a constructor? Here's my code

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);
   }
}

So my question is how to do it properly?

wieczors
  • 341
  • 1
  • 5
  • 18

1 Answers1

0

All Fields that are annotated by @FXML will be injected in the controller instance that is created by the FXMLLoader. In the constructor you can't use the Fields because the values are not injected at this moment. Use the initalize methods as shown here: http://docs.oracle.com/javafx/2/api/javafx/fxml/Initializable.html

Hendrik Ebbers
  • 2,570
  • 19
  • 34