title: Exception in thread "main" java.lang.NullPointerExceptionat Board. at<init>(Board.java:23) at PiratesDriver.main(PiratesDriver.java:14)
body: <p>hi im getting this error msg and i need help</p>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException
  at Board.&lt;init&gt;(Board.java:23)
  at PiratesDriver.main(PiratesDriver.java:14)
  </code></pre>
  
  <p>my code is</p>
  
  <pre><code>import java.util.Scanner;
  import java.util.Random;
  public class Board {
  private final int SIZE=30;
  private final int NUM_PLAYERS=2;
  **private int diffLevel;**
  private Player[] players= new Player[NUM_PLAYERS];
  private char[] hurdles=new char[SIZE];
  
  public Board() {
      System.out.println("|||||||||||||||||||||||||||||||||||||||||||||"+"\n||||||||||||||||||||START||||||||||||||||||||\n"+"|||||||||||||||||||||||||||||||||||||||||||||" );
      System.out.print("Enter Diffculty Level for the Game (0=easy, 1=50/50 i.e. not too easy, not too hard, 2=HARD):");
      **SetDifficulty();**
      System.out.println("");
      players[0].SetName(GetPlayerName(0));
      System.out.println("");
      players[1].SetName(GetPlayerName(1));
      DisplayPlayerDetails();
      System.out.println("");
      System.out.println("&lt;&lt;&lt;--GAME BOARD LEGEND--&gt;&gt;&gt;");
      System.out.println("e = This cell contains an easy enemy pirate.");
      System.out.println("t = This cell contains a treasure island.");
      System.out.println("a = This cell contains an abandoned ship.");
      System.out.println("m = This cell contains a mystery island.");
      System.out.println("j = This cell contains a magic chamber.");
      System.out.println(",P = This cell has a player in it.");
      System.out.println("&lt;&lt;&lt;------- ----- -------&gt;&gt;&gt; ");
      System.out.println("");
      SetHurdles();
      DisplayBoard();
  }
  
  **void SetDifficulty(){
      Scanner scan= new Scanner(System.in);
  
      boolean invalid = true;
      diffLevel= scan.nextInt();
      while (!((diffLevel &lt;=2) &amp;&amp; (diffLevel&gt;=0))){
          System.out.println("Error, please enter a valid value");
           diffLevel= scan.nextInt();**
  
  
      }
  
  }
  public String GetPlayerName(int index){
      Scanner scan= new Scanner(System.in);
      System.out.print("Enter Player "+(index+1)+"'s Name: ");
      String playername= scan.nextLine();
      System.out.println(playername+" has no Voodoo doll.");
      System.out.println(playername+" does not have a Ship.");
      return playername;
  }
  public void DisplayPlayerDetails(){
      System.out.println("------------- PLAYER DETAILS -------------");
      for (int i=0;i&lt;players.length;i++){
          System.out.println("--&gt;Player "+(i+1)+"&lt;--");
          System.out.println("Name: "+players[i].GetName());
          System.out.println("Health: "+players[i].GetHealth()+" potions");
          System.out.println("Treasure: "+players[i].GetWealth()+" gold coins");
          System.out.println("Weapon: "+players[i].WeaponName(players[i].GetWeapon()));
          System.out.println("Voodoo Doll: "+players[i].GetVoodoo());
          System.out.println("Ship: "+players[i].GetShip());
          System.out.println("Position: "+(players[i].GetPosition()+1));
          System.out.println("     ------&gt;&lt;------");
      }
      System.out.println("---------------------------------------------");
  
  }
  public void SetHurdles(){
      Random randNumGenerator = new Random();
      boolean bool=true;
      int rand;
      int e,h,t,a,m,j;
      if (diffLevel==0){
          e=12;
          h=0;
          }
      else if (diffLevel==1){
          e=6;
          h=6;
      }
      else {
          h=12;
          e=0;
      }
      t=6;
      a=6;
      m=3;
      j=3;
      for (int i=0;i&lt;hurdles.length;i++){
  
          while(bool){
              rand=randNumGenerator.nextInt(6);
              if (rand==0&amp;&amp; e!=0){
                  hurdles[i]='e';
                  e--;
                  bool=false;
              }
              else if (rand==1&amp;&amp; h!=0){
                  hurdles[i]='h';
                  h--;
                  bool=false;
              }
              else if (rand==2&amp;&amp; t!=0){
                  hurdles[i]='t';
                  t--;
                  bool=false;
              }
              else if (rand==3&amp;&amp; a!=0){
                  hurdles[i]='a';
                  a--;
                  bool=false;
              }
              else if (rand==4&amp;&amp; m!=0){
                  hurdles[i]='m';
                  m--;
                  bool=false;
              }
              else if (rand==5&amp;&amp; j!=0){
                  hurdles[i]='j';
                  j--;
                  bool=false;
              }
              bool=true;
          }
      }
  
      }
      public void DisplayBoard(){
          System.out.println("---------------------------------------------");
          System.out.println("********PIRATES OF 125 GAME BOARD********");
          for (int i=0;i&lt;5;i++){
              if ((players[0].GetPosition()==i)||(players[1].GetPosition()==i))
                  System.out.print((i+1)+":   "+hurdles[i]+"P");
               else 
                  System.out.print((i+1)+":   "+hurdles[i]);
          }
          System.out.println("");
          for (int i=5;i&lt;10;i++){
              if ((players[0].GetPosition()==i)||(players[1].GetPosition()==i))
                  System.out.print((i+1)+":   "+hurdles[i]+"P");
               else 
              System.out.print((i+1)+":   "+hurdles[i]);
          }
          System.out.println("");
          for (int i=10;i&lt;15;i++){
              if ((players[0].GetPosition()==i)||(players[1].GetPosition()==i))
                  System.out.print((i+1)+":   "+hurdles[i]+"P");
               else 
              System.out.print((i+1)+":  "+hurdles[i]);
          }
          System.out.println("");
          for (int i=15;i&lt;20;i++){
              if ((players[0].GetPosition()==i)||(players[1].GetPosition()==i))
                  System.out.print((i+1)+":   "+hurdles[i]+"P");
               else 
              System.out.print((i+1)+":  "+hurdles[i]);
          }
          System.out.println("");
          for (int i=20;i&lt;25;i++){
              if ((players[0].GetPosition()==i)||(players[1].GetPosition()==i))
                  System.out.print((i+1)+":   "+hurdles[i]+"P");
               else 
              System.out.print((i+1)+":  "+hurdles[i]);
          }
          System.out.println("");
          for (int i=25;i&lt;30;i++){
              if ((players[0].GetPosition()==i)||(players[1].GetPosition()==i))
                  System.out.print((i+1)+":   "+hurdles[i]+"P");
               else 
              System.out.print((i+1)+":  "+hurdles[i]);
          }
          System.out.println("");
          System.out.println("---------------------------------------------");
      }
      public void Play(){
          Board game=new Board();
          for (int i=0; i&lt;players.length;i++){
              DisplayPlayerDetails();
              while(players[i].GetPosition()&lt;hurdles.length){
  
              players[i].Move();
              if (hurdles[players[i].GetPosition()]=='e'){
                  EasyPirate e= new EasyPirate();
  
              }
              }
  
          }       
      }
  }
  </code></pre>
  
  <p>and my main drive is</p>
  
  <pre><code>public class PiratesDriver {
  
       public static void main(String[] args) {
  Board piratesOf125 = new Board(); //Instantiate a new board
  piratesOf125.Play(); //Play the game 
  
   }
  }
  </code></pre>
  
  <p>ive been trying stuff for more than an hour now, i know that the problem is with my diffLevel being null or something, but i just cant seem to be able to fix it, im guessing that i have to fix it in SetDifficulty() cause that's where diffLevel defined. need help pls.
  oh and line 14 is private int diffLevel;</p>