title: NullPointer when trying to access a Java ArrayList<User> that is NOT null
body: <p>I have an ArrayList within my UserController that stores all my User instances. </p>
  
  <p>I am able to use my setUserList to successfully set the ArrayList as I am able to loop through and print the users first name with currentUser.getFirstName()</p>
  
  <p>I trigger my Login function from a JavaFX button and I receive a NullPointer exception when simply trying to print the size of ArrayList which previously had a size of 1 and printed the users first name.</p>
  
  <p><em>UserController:</em></p>
  
  <pre><code> public class UserController {
      public ArrayList&lt;User&gt; userList;  //should contain one user thomas but gives null pointer
      //static ArrayList&lt;User&gt; userList;  //this does not return a null pointer
  
      public void setUserList(ArrayList list){
          userList = list;
          for (User user : userList) {
              User currentUser = (User) user;
              String firstName = currentUser.getFirstName();
              System.out.println("Users in the UserController: " + firstName); //prints the user thomas
          }
      }
  
      public void login(){
          try {
              System.out.println(userList.size()); //null pointer
          } catch (Exception e) {
              System.out.println(e);
          }
      }
  }
  </code></pre>
  
  <p><em>UserInterface containing login method</em></p>
  
  <pre><code>    public class UserInterface extends Application {
  
      User loggedInUser;
      UserRepo userRepo = new UserRepo();
      UserController userController = new UserController();
      Connection conn;
  
      //login.fxml
      @FXML
      public TextField InputEmailAddress;  
      @FXML
      public TextField InputPassword;  
  
      @Override
      public void start(Stage stage) throws Exception {
  
          String connectionURL = "jdbc:derby://localhost:1527/gymManager";
          String userName = "root";
          String userPassword= "root";
          try {
  
              conn = DriverManager.getConnection(connectionURL, userName, userPassword);
              if(conn != null){
                  System.out.println("Connected to the database");
                  ArrayList&lt;User&gt; list = userRepo.read(conn);
  
                  userController.setUserList(list); //here is where I set the ArrayList&lt;Users&gt; in the USerController
  
                  Parent root = FXMLLoader.load(getClass().getResource("login.fxml"));
  
                  Scene scene = new Scene(root);
  
                  stage.setScene(scene);
                  stage.show();
              }
  
          } catch(SQLException e){
              System.out.println("Exception:" + e.toString()); 
          }  
  
      }
  
      public static void main(String[] args) {
          launch(args);
      }
  
      public void login(ActionEvent event) throws Exception{
  
          userController.login();
  
      }
  
  
  
  }
  </code></pre>
  
  <p><em>login.fxml</em></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;?import java.lang.String?&gt;
  &lt;?import javafx.geometry.Insets?&gt;
  &lt;?import javafx.scene.control.Button?&gt;
  &lt;?import javafx.scene.control.Label?&gt;
  &lt;?import javafx.scene.control.TextField?&gt;
  &lt;?import javafx.scene.image.Image?&gt;
  &lt;?import javafx.scene.image.ImageView?&gt;
  &lt;?import javafx.scene.layout.Pane?&gt;
  &lt;?import javafx.scene.text.Font?&gt;
  
  &lt;Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="720.0" prefWidth="1080.0" styleClass="main-pane" xmlns:fx="http://javafx.com/fxml/1" fx:controller="classmanager.UserInterface"&gt;
     &lt;children&gt;
        &lt;Button fx:id="loginButton" layoutX="583.0" layoutY="451.0" onAction="#login"  mnemonicParsing="false" prefHeight="56.0" prefWidth="191.0" text="Log In"&gt;
           &lt;font&gt;
              &lt;Font name="Montserrat Regular" size="13.0" /&gt;
           &lt;/font&gt;
           &lt;styleClass&gt;
              &lt;String fx:value="white-btn" /&gt;
              &lt;String fx:value="bg-blue" /&gt;
              &lt;String fx:value="rounded-btn" /&gt;
           &lt;/styleClass&gt;&lt;/Button&gt;
        &lt;Button layoutX="784.0" layoutY="451.0" mnemonicParsing="false" prefHeight="56.0" prefWidth="158.0" text="I'm new here"&gt;
           &lt;font&gt;
              &lt;Font name="Montserrat Regular" size="13.0" /&gt;
           &lt;/font&gt;
           &lt;styleClass&gt;
              &lt;String fx:value="outline-btn" /&gt;
              &lt;String fx:value="rounded-btn" /&gt;
           &lt;/styleClass&gt;&lt;/Button&gt;
        &lt;Button layoutX="563.0" layoutY="514.0" mnemonicParsing="false" prefHeight="38.0" prefWidth="231.0" styleClass="transparent-btn" text="I've forgotten my password"&gt;
           &lt;font&gt;
              &lt;Font name="Montserrat Regular" size="13.0" /&gt;
           &lt;/font&gt;&lt;/Button&gt;
        &lt;Label layoutX="581.0" layoutY="273.0" prefHeight="18.0" prefWidth="411.0" text="Book classes and manage your membership details here" textFill="#9a9a9a"&gt;
           &lt;font&gt;
              &lt;Font name="Montserrat Regular" size="14.0" /&gt;
           &lt;/font&gt;
        &lt;/Label&gt;
        &lt;Label layoutX="577.0" layoutY="180.0" prefHeight="18.0" prefWidth="353.0" text="Welcome to the" textFill="#1a73b5"&gt;
           &lt;font&gt;
              &lt;Font name="Montserrat Medium" size="30.0" /&gt;
           &lt;/font&gt;
        &lt;/Label&gt;
        &lt;Label layoutX="577.0" layoutY="217.0" prefHeight="50.0" prefWidth="411.0" text="Village Hotel Gym" textFill="#1a73b5"&gt;
           &lt;font&gt;
              &lt;Font name="Montserrat Medium" size="40.0" /&gt;
           &lt;/font&gt;
        &lt;/Label&gt;
        &lt;ImageView fitHeight="730.0" fitWidth="544.0" layoutX="-25.0" layoutY="-4.0" pickOnBounds="true" preserveRatio="true"&gt;
           &lt;image&gt;
              &lt;Image url="@../login-banner.jpg" /&gt;
           &lt;/image&gt;
        &lt;/ImageView&gt;
        &lt;TextField fx:id="InputEmailAddress" layoutX="581.0" layoutY="325.0" prefHeight="50.0" prefWidth="386.0" promptText="Email address" styleClass="login-input"&gt;
           &lt;opaqueInsets&gt;
              &lt;Insets left="20.0" /&gt;
           &lt;/opaqueInsets&gt;
           &lt;font&gt;
              &lt;Font name="Montserrat Regular" size="13.0" /&gt;
           &lt;/font&gt;
        &lt;/TextField&gt;
        &lt;TextField fx:id="InputPassword" layoutX="581.0" layoutY="384.0" prefHeight="50.0" prefWidth="386.0" promptText="Password" styleClass="login-input"&gt;
           &lt;opaqueInsets&gt;
              &lt;Insets left="20.0" /&gt;
           &lt;/opaqueInsets&gt;
           &lt;font&gt;
              &lt;Font name="Montserrat Regular" size="13.0" /&gt;
           &lt;/font&gt;
        &lt;/TextField&gt;
     &lt;/children&gt;
  &lt;/Pane&gt;
  </code></pre>
  
  <p>I simply can't understand why one method (setUserList) in the UserController class will tell me that the ArrayList contains 1 user and the other (login) will return a NullPointer</p>
  
  <p>Thanks for any tips</p>