title: Populate Choicebox defined in FXML
body: <p>I'm learning <strong>javaFX</strong> and my problem is that I have simple window with some choicebox and button. This window is defined via FXML which is also associated with controller class.
  I would like to know, how to populate this choicebox with data in the controller class, because using @FXML reference to this choicebox throws<code>NullpointerEception</code></p>
  
  <p><strong>EDIT - added source code</strong>
  FXML code</p>
  
  <pre><code>&lt;AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="240.0"
          prefWidth="320.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
          fx:controller="supermarket.ManageWindowCC"&gt;
  &lt;children&gt;
      &lt;ChoiceBox fx:id="countChoiceBox" layoutX="44.0" layoutY="71.0" prefHeight="25.0" prefWidth="191.0"/&gt;
      &lt;Label layoutX="44.0" layoutY="54.0" text="To change item's count, choose one"/&gt;
      &lt;TextField layoutX="140.0" layoutY="129.0" prefHeight="25.0" prefWidth="24.0"/&gt;
      &lt;Label layoutX="123.0" layoutY="112.0" text="New count"/&gt;
      &lt;Button layoutX="126.1875" layoutY="171.5" mnemonicParsing="false" text="Submit"/&gt;
  &lt;/children&gt;
  </code></pre>
  
  <p></p>
  
  <p>Java controller code:</p>
  
  <pre><code>public class ManageWindowCC {
  @FXML
  private ChoiceBox countChoiceBox;
  
  public void onChangeCountClick(ActionEvent actionEvent) {
  
      try {
          Parent root = FXMLLoader.load(getClass().getResource("ChangeCount.fxml"));
          Stage newStage = new Stage();
          newStage.setTitle("Change item's count");
          newStage.setScene(new Scene(root, 320, 240));
          newStage.show();
          countChoiceBox = new ChoiceBox();
          countChoiceBox.setItems(FXCollections.observableArrayList("One","Two","Three"));
  
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  }
  </code></pre>
  
  <p>Thank you fro your help and time</p>