4 Replies Latest reply on Dec 3, 2012 8:33 PM by 964914

    Button not initialized

      I have a controller class which extends a simple java class. Now inside the base class I declare a button whose name matches the fx:id of the button in the fxml file. Now when the fxml is loaded the controller is initialized. however, the button is not initialized and is still null. I presume the button should have been initialized by itself.

      Sample code:
      public class TopClass {
          public TopClass () {
          private Button button1;
          private Button button2;
      public class MyController extends TopClass implements Initializable {
          public void initialize(URL url, ResourceBundle rb) {
           // do some initlization work
         button1.setDisable(true); // It throws null pointer here.
      <AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0" prefWidth="500.0" xmlns:fx="http://javafx.com/fxml" fx:controller="MyController">
          <Button id="button1" fx:id="button1" layoutX="500.0" layoutY="12.0"  prefHeight="21.0" prefWidth="100.0" text="button 1" />
          <Button id="button2" fx:id="button2" layoutX="400.0" layoutY="12.0"  prefHeight="21.0" prefWidth="100.0" text="button 2" />
      Any idea why it's not initialized. If the button is in MyController class, then buttons are initialized.