title: null pointer exception with hashmap
body: <p>this is the player class</p>
  
  <pre><code>package day6;
  
  public class Player {
  int playerId;
  
  public Player(int playerId) {
      super();
      this.playerId = playerId;
  }
  
  public int getPlayerId() {
      return playerId;
  }
  
  }
  </code></pre>
  
  <p>this is the position class</p>
  
  <pre><code>package day6;
  
  public class Position {
  
  
      private int positionNumber = 0;
  
      public Position(int positionNumber) throws Exception {
          super();
          this.positionNumber = positionNumber;
  
      }
  
      public int getPositionNumber() {
          return positionNumber;
      }
  
      }
  </code></pre>
  
  <p>this is the game class</p>
  
  <pre><code> package day6;
  
      import java.util.ArrayList;
      import java.util.HashMap;
      import java.util.List;
      import java.util.Random;
  
      public class Game {
  
  
          private int numberOfPlayers;
  
  
          HashMap&lt;Player, Position&gt; hashMapForPositionOfPlayer = new HashMap&lt;Player, Position&gt;(numberOfPlayers);
  
          @SuppressWarnings("unchecked")
          public Game(int numberOfPlayers) throws Exception {
              super();
  
              this.numberOfPlayers = numberOfPlayers;
              for (int i = 0; i &lt;numberOfPlayers; i++) {
                  hashMapForPositionOfPlayer.put(new Player(i), new Position(0));
              }
          }
  
          public void play() throws Exception {
  
              Position currentPosition;
  
  
  
  
                  for (int i = 0; i &lt; numberOfPlayers; i++) {
  
                      Player player = new Player(i);
                      currentPosition = hashMapForPositionOfPlayer.get(player);
                      int value = currentPosition.getPositionNumber();
  
                      }
                  }
              }
  </code></pre>
  
  <p>I tried to run the program Game class and game.play() but it is showing null value to the 0th value of the hashmap.</p>
  
  <p>it means currentPosition=null for hashmap of key value 0.</p>
  
  <p>Help me..</p>