Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8333625

Typo in FXML docs example: "resources" type should be ResourceBundle

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      When implementing Initializable in the JavaFX controller, the abstract method initialize should be @Override public void initialize(URL url, ResourceBundle rb){...} and not @Override public void initialize(URL url, Resource r){...}.

      The full incorrect code in docs
      package com.foo;

      public class MyController implements Initializable {
          public Button button;

          @Override
          public void initialize(URL location, Resources resources)
              button.setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent event) {
                      System.out.println("You clicked me!");
                  }
              });
          }
      }

      What it should be.
      package com.foo;

      public class MyController implements Initializable {
          public Button button;

          @Override
          public void initialize(URL location, ResourceBundle resources)
              button.setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent event) {
                      System.out.println("You clicked me!");
                  }
              });
          }
      }

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      View the docs at https://openjfx.io/javadoc/22/javafx.fxml/javafx/fxml/doc-files/introduction_to_fxml.html.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I expected to see the following.

      package com.foo;

      public class MyController implements Initializable {
          public Button button;

          @Override
          public void initialize(URL location, ResourceBundle resources)
              button.setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent event) {
                      System.out.println("You clicked me!");
                  }
              });
          }
      }
      ACTUAL -
      I currently see the following.

      package com.foo;

      public class MyController implements Initializable {
          public Button button;

          @Override
          public void initialize(URL location, Resources resources)
              button.setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent event) {
                      System.out.println("You clicked me!");
                  }
              });
          }
      }

            kcr Kevin Rushforth
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: