title: ArrayList add null pointer
body: <p>The following class keeps giving me a null pointer when I try to call the addPlayer method and I have no idea what the heck I'm doing wrong. : Keep in mind this is really simple stuff...supposedly... I'm learning Java. </p>
  
  <pre><code>import java.util.*;
  
  public class Team {
  
      private String teamName;
      private  ArrayList&lt;Player&gt; players;
      private int numberOfPlayers; 
  
      public Team(String teamName) {
  
          this.teamName = teamName;
  
      }
  
      public String getName() {
  
          return this.teamName;
  
      }
  
      public void addPlayer(Player player) {
          this.players.add(player);
          }
  
  
      public void printPlayers() {
  
          for (Player player : this.players) {
              System.out.println(player);
          }
      }
  }
  </code></pre>
  
  <p>Here is the Player class :</p>
  
  <pre><code>public class Player {
  
      private String name;
      private int goals;
  
      public Player(String name) {
          this.name = name;
      }
  
      public Player(String name, int goals) {
  
          this.name = name;
          this.goals = goals;
      }
  
      @Override
      public String toString() {
  
          return this.getName() + ", goals " + this.goals();
      }
  
      public String getName () {
          return this.name; 
      }
  
      public int goals() {
          return this.goals; 
      }
  
  }
  </code></pre>