title: Changing data in an Object Array
body: <p>I have been trying to make a game for a friend, but I'm having a problem with getting my line <code>player[i].setName(getName(pn));</code> in class <code>Players</code> to work. I want to be able to set the names of the players, or change them, in the list. but I keep getting errors at this line. This happened after i changed the <code>public</code> variables in class <code>Player</code> from <code>static</code>.</p>
  
  <blockquote>
    <p>"Exception in thread "main" java.lang.NullPointerException
        at worldhomicide.drinkinggame.PlayerInfo.Players.setPlayers(Players.java:16)
        at worldhomicide.drinkinggame.main.Game.main(Game.java:25)"</p>
  </blockquote>
  
  <p>Any help would be greatly appreciated! I posted all needed code below.</p>
  
  <p><strong>Game Class</strong> </p>
  
  <pre><code>public class Game{
  
      public static void main(String[] args) {
  
          MessageHandler.gameRules(); // Display Game Information
          Players.getAmount();Players.setPlayers();   // Get player data
  
          System.out.println("What player would you like to look up?");
          int choice = Integer.parseInt(EventHandler.keyboard.next()); choice -= 1;
          System.out.println(Players.player[choice].name);
  
  
      }
  
  }
  </code></pre>
  
  <p><strong>Players Class</strong></p>
  
  <pre><code>public class Players extends EventHandler {
  
      public static int playerAmount;
      public static Player[] player;
  
      public static void setPlayers(){    
          player = new Player[playerAmount];
  
          for(int i = 0; i &lt; player.length; i++){
              int pn = i+1;
              player[i].setName(getName(pn));
          }
      }
  
      public static void getAmount(){
          MessageHandler.playerAmount();
          playerAmount = Integer.parseInt(keyboard.next());
      }
  
  
  }
  </code></pre>
  
  <p><strong>Class EventHandler</strong></p>
  
  <pre><code>public class EventHandler {
  
      public static Scanner keyboard = new Scanner(System.in);
  
      public static String getName(int playerNumber){
          System.out.println("What is player " + playerNumber + "'s name?");
          String name = keyboard.next();      
          return name;
  
      }
  
  }
  </code></pre>
  
  <p><strong>Player Class</strong></p>
  
  <pre><code>public class Player {
  
      public String name;
      public int score;
  
      public void setName(String name){
          this.name = name;
      }
  
  }
  </code></pre>