title: How do I pass a value to a method that calls a new page in the Controller class of the method?
body: <p>I have a pane with 10 films, and every time the user clicks on a film thumbnail, I have a method that will take the user to a tickets page where they can select how many tickets they'd like to buy. However, I'm trying to figure out how to pass the Film object <code>loadTicketPage</code> in the Controller class for the called tickets page, when I call the film object from the movie page Controller. </p>
  
  <pre><code>public class controller {
      public void initialize() {
          film1.setImage(getFilmFromList(0).getThumbnail());
          film2.setImage(getFilmFromList(1).getThumbnail());
          film3.setImage(getFilmFromList(2).getThumbnail());
          film4.setImage(getFilmFromList(3).getThumbnail());
          film5.setImage(getFilmFromList(4).getThumbnail());
          film6.setImage(getFilmFromList(5).getThumbnail());
          film7.setImage(getFilmFromList(6).getThumbnail());
          film8.setImage(getFilmFromList(7).getThumbnail());
          film9.setImage(getFilmFromList(8).getThumbnail());
          film10.setImage(getFilmFromList(9).getThumbnail());
  
      }
  
      public void loadTicketPage(Film film) {
          try {
              Parent root = FXMLLoader.load(getClass().getResource("ticketsPage.fxml"));
  
              Scene scene = new Scene(root);
              Stage stage = new Stage();
  
              stage.initModality(Modality.APPLICATION_MODAL);
  
              stage.setScene(scene);
              stage.setTitle("Ticket Page");
              stage.show();
  
          } catch (IOException e) {
              System.out.println(e);
          }
      }
  
      public void film1() {
          Double price = getFilmFromList(0).getPrice();
          String title = getFilmFromList(0).getFilmName();
          loadTicketPage(getFilmFromList(0));
  
      }
  
      public void film2() {
          Double price = getFilmFromList(1).getPrice();
          String title = getFilmFromList(1).getFilmName();
          loadTicketPage(getFilmFromList(1));
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>public class TicketsPageController {
      public Label filmName;
      public Label filmDescription;
  
      public void initialize() {
          filmName.setText(film.getFilmTitle)
      }
  }
  </code></pre>
  
  <p>Here is fxml file for the ticketsPage:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;?import java.lang.String?&gt;
  &lt;?import javafx.collections.FXCollections?&gt;
  &lt;?import javafx.scene.control.Button?&gt;
  &lt;?import javafx.scene.control.ComboBox?&gt;
  &lt;?import javafx.scene.control.Label?&gt;
  &lt;?import javafx.scene.effect.SepiaTone?&gt;
  &lt;?import javafx.scene.image.Image?&gt;
  &lt;?import javafx.scene.image.ImageView?&gt;
  &lt;?import javafx.scene.layout.AnchorPane?&gt;
  &lt;?import javafx.scene.text.Font?&gt;
  
  &lt;AnchorPane prefHeight="670.0" prefWidth="1000.0" style="-fx-background-color: maroon;" xmlns="http://javafx.com/javafx/8.0.172-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.TicketsPageController"&gt;
     &lt;children&gt;
        &lt;Label fx:id="lblHello" layoutX="308.0" layoutY="9.0" prefHeight="94.0" prefWidth="460.0" text="Hello! Welcome to Cinema Enterpriso" textAlignment="CENTER" textFill="WHITE" wrapText="true"&gt;
           &lt;font&gt;
              &lt;Font name="Broadway" size="30.0" /&gt;
           &lt;/font&gt;
        &lt;/Label&gt;
        &lt;ImageView fitHeight="141.0" fitWidth="297.0" layoutX="10.0" layoutY="10.0" pickOnBounds="true" preserveRatio="true"&gt;
           &lt;image&gt;
              &lt;Image url="@images/University_of_Huddersfield_logo.jpg" /&gt;
           &lt;/image&gt;
        &lt;/ImageView&gt;
        &lt;Button fx:id="btnOpenLogin" layoutX="770.0" layoutY="46.0" mnemonicParsing="false" onAction="#btnOpenLoginClick" style="-fx-background-color: tan;" text="Login"&gt;
           &lt;effect&gt;
              &lt;SepiaTone /&gt;
           &lt;/effect&gt;
        &lt;/Button&gt;
        &lt;Button fx:id="btnSignUp" layoutX="840.0" layoutY="46.0" mnemonicParsing="false" onAction="#btnCreateNewUser" style="-fx-background-color: tan;" text="Sign Up"&gt;
           &lt;effect&gt;
              &lt;SepiaTone /&gt;
           &lt;/effect&gt;
        &lt;/Button&gt;
        &lt;Button fx:id="btnBasket" layoutX="925.0" layoutY="46.0" mnemonicParsing="false" onAction="#btnOpenOrderSummary" style="-fx-background-color: tan;" text="Basket"&gt;
           &lt;effect&gt;
              &lt;SepiaTone /&gt;
           &lt;/effect&gt;
        &lt;/Button&gt;
        &lt;Label layoutX="35.0" layoutY="328.0" text="Please select your tickets:" textFill="WHITE"&gt;
           &lt;font&gt;
              &lt;Font name="Broadway" size="24.0" /&gt;
           &lt;/font&gt;
        &lt;/Label&gt;
        &lt;ComboBox fx:id="ticketType1" layoutX="51.0" layoutY="383.0" prefWidth="150.0" promptText="Ticket type" style="-fx-background-color: tan;"&gt;
           &lt;effect&gt;
              &lt;SepiaTone /&gt;
           &lt;/effect&gt;
           &lt;items&gt;
              &lt;FXCollections fx:factory="observableArrayList"&gt;
                 &lt;String fx:value="Adult"&gt; &lt;/String&gt;
                 &lt;String fx:value="Child"&gt; &lt;/String&gt;
                 &lt;String fx:value="Teen"&gt; &lt;/String&gt;
                 &lt;String fx:value="Student"&gt; &lt;/String&gt;
                 &lt;String fx:value="Senior"&gt; &lt;/String&gt;
              &lt;/FXCollections&gt;
           &lt;/items&gt;
        &lt;/ComboBox&gt;
        &lt;ComboBox fx:id="ticketType2" layoutX="51.0" layoutY="437.0" prefWidth="150.0" promptText="Ticket type" style="-fx-background-color: tan;"&gt;
           &lt;effect&gt;
              &lt;SepiaTone /&gt;
           &lt;/effect&gt;
           &lt;items&gt;
              &lt;FXCollections fx:factory="observableArrayList"&gt;
                 &lt;String fx:value="Adult"&gt; &lt;/String&gt;
                 &lt;String fx:value="Child"&gt; &lt;/String&gt;
                 &lt;String fx:value="Teen"&gt; &lt;/String&gt;
                 &lt;String fx:value="Student"&gt; &lt;/String&gt;
                 &lt;String fx:value="Senior"&gt; &lt;/String&gt;
              &lt;/FXCollections&gt;
           &lt;/items&gt;
        &lt;/ComboBox&gt;
        &lt;ComboBox fx:id="ticketType3" layoutX="51.0" layoutY="489.0" prefWidth="150.0" promptText="Ticket type" style="-fx-background-color: tan;"&gt;
           &lt;effect&gt;
              &lt;SepiaTone /&gt;
           &lt;/effect&gt;
           &lt;items&gt;
              &lt;FXCollections fx:factory="observableArrayList"&gt;
                 &lt;String fx:value="Adult"&gt; &lt;/String&gt;
                 &lt;String fx:value="Child"&gt; &lt;/String&gt;
                 &lt;String fx:value="Teen"&gt; &lt;/String&gt;
                 &lt;String fx:value="Student"&gt; &lt;/String&gt;
                 &lt;String fx:value="Senior"&gt; &lt;/String&gt;
              &lt;/FXCollections&gt;
           &lt;/items&gt;
        &lt;/ComboBox&gt;
        &lt;ComboBox fx:id="ticketType4" layoutX="51.0" layoutY="541.0" prefWidth="150.0" promptText="Ticket type" style="-fx-background-color: tan;"&gt;
           &lt;effect&gt;
              &lt;SepiaTone /&gt;
           &lt;/effect&gt;
           &lt;items&gt;
              &lt;FXCollections fx:factory="observableArrayList"&gt;
                 &lt;String fx:value="Adult"&gt; &lt;/String&gt;
                 &lt;String fx:value="Child"&gt; &lt;/String&gt;
                 &lt;String fx:value="Teen"&gt; &lt;/String&gt;
                 &lt;String fx:value="Student"&gt; &lt;/String&gt;
                 &lt;String fx:value="Senior"&gt; &lt;/String&gt;
              &lt;/FXCollections&gt;
           &lt;/items&gt;
        &lt;/ComboBox&gt;
        &lt;ComboBox fx:id="ticketType5" layoutX="51.0" layoutY="592.0" prefWidth="150.0" promptText="Ticket type" style="-fx-background-color: tan;"&gt;
           &lt;effect&gt;
              &lt;SepiaTone /&gt;
           &lt;/effect&gt;
            &lt;items&gt;
                &lt;FXCollections fx:factory="observableArrayList"&gt;
                    &lt;String fx:value="Adult"&gt; &lt;/String&gt;
                    &lt;String fx:value="Child"&gt; &lt;/String&gt;
                    &lt;String fx:value="Teen"&gt; &lt;/String&gt;
                    &lt;String fx:value="Student"&gt; &lt;/String&gt;
                    &lt;String fx:value="Senior"&gt; &lt;/String&gt;
                &lt;/FXCollections&gt;
            &lt;/items&gt;
        &lt;/ComboBox&gt;
        &lt;ComboBox fx:id="no1" layoutX="218.0" layoutY="383.0" prefHeight="31.0" prefWidth="79.0" promptText="no." style="-fx-background-color: tan;"&gt;
           &lt;effect&gt;
              &lt;SepiaTone /&gt;
           &lt;/effect&gt;
           &lt;items&gt;
              &lt;FXCollections fx:factory="observableArrayList"&gt;
                 &lt;String fx:value="1"&gt; &lt;/String&gt;
                 &lt;String fx:value="2"&gt; &lt;/String&gt;
                 &lt;String fx:value="3"&gt; &lt;/String&gt;
                 &lt;String fx:value="4"&gt; &lt;/String&gt;
                 &lt;String fx:value="5"&gt; &lt;/String&gt;
                 &lt;String fx:value="6"&gt; &lt;/String&gt;
              &lt;/FXCollections&gt;
           &lt;/items&gt;
        &lt;/ComboBox&gt;
        &lt;ComboBox fx:id="no2" layoutX="217.0" layoutY="435.0" prefHeight="31.0" prefWidth="79.0" promptText="no." style="-fx-background-color: tan;"&gt;
  
           &lt;effect&gt;
              &lt;SepiaTone /&gt;
           &lt;/effect&gt;
           &lt;items&gt;
              &lt;FXCollections fx:factory="observableArrayList"&gt;
                 &lt;String fx:value="1"&gt; &lt;/String&gt;
                 &lt;String fx:value="2"&gt; &lt;/String&gt;
                 &lt;String fx:value="3"&gt; &lt;/String&gt;
                 &lt;String fx:value="4"&gt; &lt;/String&gt;
                 &lt;String fx:value="5"&gt; &lt;/String&gt;
                 &lt;String fx:value="6"&gt; &lt;/String&gt;
              &lt;/FXCollections&gt;
           &lt;/items&gt;
        &lt;/ComboBox&gt;
        &lt;ComboBox fx:id="no3" layoutX="217.0" layoutY="488.0" prefHeight="31.0" prefWidth="79.0" promptText="no." style="-fx-background-color: tan;"&gt;
           &lt;effect&gt;
              &lt;SepiaTone /&gt;
           &lt;/effect&gt;
           &lt;items&gt;
              &lt;FXCollections fx:factory="observableArrayList"&gt;
                 &lt;String fx:value="1"&gt; &lt;/String&gt;
                 &lt;String fx:value="2"&gt; &lt;/String&gt;
                 &lt;String fx:value="3"&gt; &lt;/String&gt;
                 &lt;String fx:value="4"&gt; &lt;/String&gt;
                 &lt;String fx:value="5"&gt; &lt;/String&gt;
                 &lt;String fx:value="6"&gt; &lt;/String&gt;
              &lt;/FXCollections&gt;
           &lt;/items&gt;
        &lt;/ComboBox&gt;
        &lt;ComboBox fx:id="no4" layoutX="218.0" layoutY="542.0" prefHeight="31.0" prefWidth="79.0" promptText="no." style="-fx-background-color: tan;"&gt;
           &lt;effect&gt;
              &lt;SepiaTone /&gt;
           &lt;/effect&gt;
           &lt;items&gt;
              &lt;FXCollections fx:factory="observableArrayList"&gt;
                 &lt;String fx:value="1"&gt; &lt;/String&gt;
                 &lt;String fx:value="2"&gt; &lt;/String&gt;
                 &lt;String fx:value="3"&gt; &lt;/String&gt;
                 &lt;String fx:value="4"&gt; &lt;/String&gt;
                 &lt;String fx:value="5"&gt; &lt;/String&gt;
                 &lt;String fx:value="6"&gt; &lt;/String&gt;
              &lt;/FXCollections&gt;
           &lt;/items&gt;
        &lt;/ComboBox&gt;
        &lt;ComboBox fx:id="no5" layoutX="217.0" layoutY="594.0" prefHeight="31.0" prefWidth="79.0" promptText="no." style="-fx-background-color: tan;"&gt;
           &lt;effect&gt;
              &lt;SepiaTone /&gt;
           &lt;/effect&gt;
           &lt;items&gt;
              &lt;FXCollections fx:factory="observableArrayList"&gt;
                 &lt;String fx:value="1"&gt; &lt;/String&gt;
                 &lt;String fx:value="2"&gt; &lt;/String&gt;
                 &lt;String fx:value="3"&gt; &lt;/String&gt;
                 &lt;String fx:value="4"&gt; &lt;/String&gt;
                 &lt;String fx:value="5"&gt; &lt;/String&gt;
                 &lt;String fx:value="6"&gt; &lt;/String&gt;
              &lt;/FXCollections&gt;
           &lt;/items&gt;
        &lt;/ComboBox&gt;
        &lt;Label fx:id="filmName" layoutX="521.0" layoutY="123.0" text="Film" textFill="WHITE"&gt;
           &lt;font&gt;
              &lt;Font name="Broadway" size="30.0" /&gt;
           &lt;/font&gt;
        &lt;/Label&gt;
        &lt;Label fx:id="filmDescription" layoutX="485.0" layoutY="189.0" text="Description" textFill="WHITE"&gt;
           &lt;font&gt;
              &lt;Font name="Broadway" size="24.0" /&gt;
           &lt;/font&gt;
        &lt;/Label&gt;
        &lt;Button fx:id="btnAddToOrder1" layoutX="325.0" layoutY="383.0" mnemonicParsing="false" onAction="#btnAddTicketToOrder1" style="-fx-background-color: tan;" text="Add to order" textFill="MAROON"&gt;
           &lt;effect&gt;
              &lt;SepiaTone /&gt;
           &lt;/effect&gt;
        &lt;/Button&gt;
        &lt;Button fx:id="btnAddToOrder2" layoutX="325.0" layoutY="435.0" mnemonicParsing="false" onAction="#btnAddTicketToOrder2" style="-fx-background-color: tan;" text="Add to order" textFill="MAROON"&gt;
           &lt;effect&gt;
              &lt;SepiaTone /&gt;
           &lt;/effect&gt;
        &lt;/Button&gt;
        &lt;Button fx:id="btnAddToOrder3" layoutX="325.0" layoutY="489.0" mnemonicParsing="false" onAction="#btnAddTicketToOrder3" style="-fx-background-color: tan;" text="Add to order" textFill="MAROON"&gt;
           &lt;effect&gt;
              &lt;SepiaTone /&gt;
           &lt;/effect&gt;
        &lt;/Button&gt;
        &lt;Button fx:id="btnAddToOrder4" layoutX="325.0" layoutY="541.0" mnemonicParsing="false" onAction="#btnAddTicketToOrder4" style="-fx-background-color: tan;" text="Add to order" textFill="MAROON"&gt;
           &lt;effect&gt;
              &lt;SepiaTone /&gt;
           &lt;/effect&gt;
        &lt;/Button&gt;
        &lt;Button fx:id="btnAddToOrder5" layoutX="325.0" layoutY="595.0" mnemonicParsing="false" onAction="#btnAddTicketToOrder5" style="-fx-background-color: tan;" text="Add to order" textFill="MAROON"&gt;
           &lt;effect&gt;
              &lt;SepiaTone /&gt;
           &lt;/effect&gt;
        &lt;/Button&gt;
        &lt;Button fx:id="btnBackHomepage" layoutX="485.0" layoutY="594.0" mnemonicParsing="false" onAction="#btnBackToHomePageClick" prefHeight="31.0" prefWidth="155.0" style="-fx-background-color: tan;" text="Back to Homepage" textFill="MAROON"&gt;
           &lt;effect&gt;
              &lt;SepiaTone /&gt;
           &lt;/effect&gt;
        &lt;/Button&gt;
     &lt;/children&gt;
  &lt;/AnchorPane&gt;
  </code></pre>
  
  <p>Here is the stacktrace:</p>
  
  <pre><code>Caused by: java.lang.reflect.InvocationTargetException
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
      at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
      at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2566)
      ... 45 more
  Caused by: java.lang.NullPointerException
      at sample.TicketsPageController.setStuff(TicketsPageController.java:54)
      at sample.TicketsPageController.initialize(TicketsPageController.java:41)
      ... 55 more
  </code></pre>
  
  <p>Here is my TicketPageController</p>
  
  <pre><code>package sample;
  
  import javafx.event.ActionEvent;
  import javafx.fxml.FXMLLoader;
  import javafx.scene.Parent;
  import javafx.scene.control.Button;
  import javafx.scene.control.ComboBox;
  import javafx.scene.control.Label;
  import javafx.stage.Window;
  
  import java.io.IOException;
  
  public class TicketsPageController {
      public Label lblHello;
      public Button btnOpenLogin;
      public Button btnSignUp;
      public Button btnBasket;
      public Label filmName;
      public Label filmDescription;
      public ComboBox ticketType1;
      public ComboBox ticketType2;
      public ComboBox ticketType3;
      public ComboBox ticketType4;
      public ComboBox ticketType5;
      public ComboBox no1;
      public ComboBox no2;
      public ComboBox no3;
      public ComboBox no4;
      public ComboBox no5;
      public Button btnAddToOrder1;
      public Button btnAddToOrder2;
      public Button btnAddToOrder3;
      public Button btnAddToOrder4;
      public Button btnAddToOrder5;
      public Button btnBackHomepage;
      private String filmTitle;
  
      private Film film;
  
      public void initialize() {
            setStuff();
  //        System.out.println(filmTitle);
            filmName.setText(filmTitle);
      }
  
  //    public void setFilm(Film film) {
  //        System.out.println("in set film");
  //        this.film = film;
  //
  //    }
  
      public void setFilm(Film film) {
          this.film = film;
          filmName.setText(film.getFilmName());
      }
  
      public void setStuff() {
          System.out.println("test");
          filmTitle = film.getFilmName();
      }
  
      public String printFilm(){
          return film.getFilmName();
      }
  
      public void btnOpenLoginClick(ActionEvent actionEvent) {
          printFilm();
      }
  
      public void btnCreateNewUser(ActionEvent actionEvent) {
      }
  
      public void btnOpenOrderSummary(ActionEvent actionEvent) {
      }
  
      public void btnAddTicketToOrder1(ActionEvent actionEvent) {
      }
  
      public void btnAddTicketToOrder2(ActionEvent actionEvent) {
      }
  
      public void btnAddTicketToOrder3(ActionEvent actionEvent) {
      }
  
      public void btnAddTicketToOrder4(ActionEvent actionEvent) {
      }
  
      public void btnAddTicketToOrder5(ActionEvent actionEvent) {
      }
  
      public void btnBackToHomePageClick(ActionEvent actionEvent) throws IOException {
          Window mainWindow = btnBackHomepage.getScene().getWindow();
          Parent newRoot = FXMLLoader.load(getClass().getResource("homepage.fxml"));
          mainWindow.getScene().setRoot(newRoot);
      }
  }
  </code></pre>