title: Null Pointer Exception for Assignment
body: <p>So I know where the the Null Point exception is happening (Eclipse is helpful that way)</p>
  
  <p>I have the following classes:</p>
  
  <pre><code>/**
   * Card class - a typical playing card.
   * 
   * @author Colleen 
   * @version 2010.03.09
   */
  public class Card
  {
      private String suit;
      private int value;
      private String description;
      private static final String[] SUITS = {"Hearts", "Diamonds", "Spades", "Clubs"};
      private static final String[] DESCRIPTIONS = {
              "Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten",
              "Jack", "Queen", "King"};
  
      public Card(){
          suit = "Spades";
          value = 0;
          description = "Joker";
      }
  
      public Card(String description, String suit){
          setSuit(suit);
          setValue(description);
          setDescription(description);
      }
  
      /**
       * @return the suit
       */
      public String getSuit() {
          return suit;
      }
  
      /**
       * @param suit the suit to set
       */
       public void setSuit(String suit) {
          int count = 0;
          boolean check = false;
          while(count &lt; SUITS.length){
              if(suit == SUITS[count]){
                  check = true;
              }
              count ++;
          }
          if(check == true){
              this.suit = suit;
          } else {
              suit = "Spades";
          }
       }
  
      /**
       * @return the value
       */
      public int getValue() {
          return value;
      }
  
      /**
      * @param value the value to set
      */
      public void setValue(String description) {
          if(description == "Two"){
              value = 2;
          } else if(description == "Three"){
              value = 3;
          } else if(description == "Four"){
              value = 4;
          } else if(description == "Five"){
              value = 5;
          } else if(description == "Six"){
              value = 6;
          } else if(description == "Sever"){
              value = 7;
          } else if(description == "Eight"){
              value = 8;
          }else if(description == "Nine"){
              value = 9;
          } else if(description == "Ten" || description == "Jack" || description == "Queen" ||  description == "King"){
              value = 10;
          } else if(description == "Ace"){
              value = 11;
          } else {
              description = "Joker";
              value = 0;
          }
      }
  
      /**
       * @return the description
       */
      public String getDescription() {
          return description;
      }
  
      /**
       * @param description the description to set
       */
      public void setDescription(String description) {
          int count = 0;
          boolean check = false;
          while(count &lt; DESCRIPTIONS.length){
              if(description == DESCRIPTIONS[count]){
                  check = true;
              } 
              count ++;
          }
          if(check == true){
              this.description = description;
          } else {
              description = "Joker";
          }
       }
   }
  </code></pre>
  
  <p>Next Class:</p>
  
  <pre><code> import java.util.ArrayList;
   import java.util.Collections;
   import java.util.Random;
  
   /**
    * Deck of cards.
    * 
    * @author Bullwinkle J. Moose
    * @version (June 11, 2012)
    */
   public class Deck
   {
       private ArrayList&lt;Card&gt; deck;
       private static final int TIMES_TO_SHUFFLE = 5;
       private static final String[] SUITS = {"Hearts", "Diamonds", "Spades", "Clubs"};
       private static final String[] DESCRIPTIONS = {
               "Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten",
               "Jack", "Queen", "King"};
  
       /**
        * Constructor for objects of class Deck
        * Creates a new container for Card objects
        */
       public Deck()
       {
           deck = new ArrayList&lt;Card&gt;();
       }
  
       /**
        * Add a card to the deck.
        * @param Card to be added
        */
       public void addCard(Card cardToAdd)
       {
           deck.add(cardToAdd);
       }
  
       /**
        * Take the first card from the deck.
        * @return Card or null
        */
       public Card takeCard()
       {
           if(deck.isEmpty()) {
               return null; 
           }
           else {  // get the top card
              return deck.remove(0);
           }
       }
  
       public int deckSize(){
          int deckSize = deck.size();
          return deckSize;
       }
  
       /**
        * Show the contents of the deck.
        */
       public void showDeck(){
           for(Card eachCard : deck) {
               System.out.println(eachCard.getDescription() + " of " + eachCard.getSuit());
           }
       }
  
       /**
        * Method that switch the index position in the deck of the two cards.
        */
       public void swap(int firstNumber, int secondNumber){        
           if (firstNumber &gt;= 0 &amp;&amp; firstNumber &lt; deck.size()) {
               if (secondNumber &gt;= 0 &amp;&amp; secondNumber &lt; deck.size()) {
                   Collections.swap(deck,firstNumber,secondNumber);
               } else {
                   System.out.println("Invalid index entry ...");
               }
           } else {
               System.out.println("Invalid index entry ...");
           }
       }
  
       /**
       * Method that randomly selects two numbers between 0 (inclusive) and the size of the deck (exclusive),
        * and passes those numbers as parameters to swap(). This must be within a loop, so that the 
        * swap() method is called TIMES_TO_SHUFFLE times.
        */    
       public void shuffle(){
           Random randomGenerator = new Random();
           int counter = 0;
           int firstNumber, secondNumber = 0;
           while (counter++ &lt; TIMES_TO_SHUFFLE){
               firstNumber = randomGenerator.nextInt(deck.size());
               secondNumber = randomGenerator.nextInt(deck.size());
               swap(firstNumber,secondNumber);
          }    
       }
  
       public void loadDeck() {
           for (int suit = 0; suit &lt; SUITS.length; suit++) {
               for (int description = 0; description &lt; DESCRIPTIONS.length; description++) {
                   Card card = new Card(DESCRIPTIONS[description], SUITS[suit]);
                   deck.add(card);
               }
           }
       }
   }
  </code></pre>
  
  <p>And final class:</p>
  
  <pre><code> import java.util.ArrayList;
  
   /**
    * @author jaimefenton
    *
    */
   public class Game {
  
       private Deck aDeck;
       private InputReader reader;
       private ArrayList&lt;Card&gt; hand;
       private String commandChoice;
  
       /**
        * Method to run the game. 
        * First while loop will run until the player chooses "no" for another round.
        * Second while look will keep running until the player chooses to stand, has 21 or busts.
        * the last while loop is to make sure that the player chooses either "Hit" or "Stand". If neither is choosen, it will keep requesting it.
        */
       public void Play(){
          int playerPoints = 0;
          int totalRounds = 0;
  
          intro();
          aDeck = new Deck();
          aDeck.loadDeck();
          while(anotherRound() == false){
              dealCard();
              dealCard();
              showHand();
              report();
              while(isStanding() == false){
                  if(hasBlackjack() == true){
                          hasBlackjack();
                  System.out.println("BlackJack!");
                  }else if (isBusted() == true){
                      isBusted();
                      System.out.println("You have Busted!");
                  }else {
                      dealCard();
                      report();
                      System.out.println("Your choice: Hit or Stand? ");
                      String inputChoice = reader.getInput();
                      while(inputChoice != "Hit" || inputChoice != "Stand"){
                          System.out.println("That is not a correct choice.");
                      }
                      isStanding();
                  }
  
           } totalRounds ++;
          }
          System.out.println("Player Points: " + playerPoints);
           System.out.println("Total Rounds: " + totalRounds);
       }
  
       /**
        * intro message to player
        */
       public void intro(){
          System.out.println("Welcome to 1451 Blackjack!");
          System.out.println("You will start with two cards.");
          System.out.println("You will be prompted to 'hit' or 'stand' 'hit' means you want another card, 'stand' not.");
          System.out.println("");
          System.out.println("You are trying to get Blackjack with exactly 21 points.");
  
       }
       /**
        * deals a card to the player
        */
       public void dealCard(){
          int deckSize = aDeck.deckSize();
          if(deckSize == 0){
              System.out.println("Time for some more cards");
              aDeck.loadDeck();
              aDeck.shuffle();
           } else {
           Card tempCard = aDeck.takeCard();
           hand.add(tempCard);
           }
       }
  
       /**
        * calculates the hand value of the player
        * @return handValue
        */
       public int getHandValue(){
          int handValue = 0;
          for(Card eachCard : hand) {
               int tempValue = eachCard.getValue();
               handValue = handValue + tempValue;
           }
          return handValue;
       }
  
       /**
        * displays contents of players hand
        */
      public void showHand(){
          System.out.println("Your cards:"); 
           for(Card eachCard : hand) {
                   System.out.println(eachCard.getDescription()+ 
                                   " of " + eachCard.getSuit());
               }
       }
  
       /**
        * displays contents of hand
        * @return true or false
        */
      public boolean hasBlackjack(){
          int bjValue = getHandValue(); 
          if(bjValue == 21){
              return true;
          } else {
              return false;
          }
       }
  
       /**
        * is hand value above 21?
        */
  
       public boolean isBusted(){
          int bjValue = getHandValue(); 
          if(bjValue &gt; 21){
              return true;
           } else {
              return false;
           }
       }
  
       /**
        * has player chosen to "stand"?
        * @return true or false
        */
       public boolean isStanding(){
          if(commandChoice == "Hit"){
              return true;
          } else {
              return false;
          }
       }
  
       public boolean anotherRound(){
          if(commandChoice == "no"){
              return true;
          } else {
              return false;
          }
       }
  
       /**
        * final report of points
        */
       public void report(){
          showHand();
          System.out.println("Hand Value: " + getHandValue());
          System.out.println(""); 
       }
   }
  </code></pre>
  
  <p>I've not included the InputReader as it's not important for this question. </p>
  
  <p>I'm using a driver class that's tested both <code>Deck</code> and <code>Card</code> thoroughly and all returned positive results. Bear in mind, I'm aware the <code>play()</code> is probably messed up, but until I resolve the methods it's calling, I won't be able to fix it. </p>
  
  <p>The first error I hit is with "<code>public void dealCard()</code>". It's pulling a null point exception error relating to "<code>if(deckSize == 0)</code>". I can't tell why it's not working, because when I run it directly from deck, it works perfectly. Once that issues resolved, I'm fairly certain I can work out the rest. </p>
  
  <p>Thanks for checking this out.</p>