title: Why it keeps on telling me "variable card might not have been initialized"
body: <p>This is a java poker game project. At the beginning, I defined the Card class. </p>
  
  <pre><code>class Card {
  
  /* constant suits and ranks */
  static final String[] Suit = {"Clubs", "Diamonds", "Hearts", "Spades" };
  static final String[] Rank = {"","A","2","3","4","5","6","7","8","9","10","J","Q","K"};
  
  /* Data field of a card: rank and suit */
  private int cardRank;  /* values: 1-13 (see Rank[] above) */
  private int cardSuit;  /* values: 0-3  (see Suit[] above) */
  
  /* Constructor to create a card */
  /* throw MyPlayingCardException if rank or suit is invalid */
  public Card(int rank, int suit) throws MyPlayingCardException { 
  if ((rank &lt; 1) || (rank &gt; 13))
      throw new MyPlayingCardException("Invalid rank:"+rank);
  else
          cardRank = rank;
  if ((suit &lt; 0) || (suit &gt; 3))
      throw new MyPlayingCardException("Invalid suit:"+suit);
  else
          cardSuit = suit;
  }
  
  /* Accessor and toString */
  /* You may impelemnt equals(), but it will not be used */
  public int getRank() { return cardRank; }
  public int getSuit() { return cardSuit; }
  public String toString() { return Rank[cardRank] + " " + Suit[cardSuit]; }
  </code></pre>
  
  <p>Then, I tried to define Deck class to hold the Card. But I get problem in the Deck constructor. It keeps on telling me "variable card may not be initialized". I think I have already initialized it at the beginning of the constructor. What gives me error? </p>
  
  <pre><code>class Decks {
  
  /* this is used to keep track of original n*52 cards */
  private List&lt;Card&gt; originalDecks;   
  
  /* this starts with n*52 cards deck from original deck   */
  /* it is used to keep track of remaining cards to deal */
  /* see reset(): it resets dealDecks to a full deck      */
  private List&lt;Card&gt; dealDecks;
  
  /* number of decks in this object */
  private int numberDecks;
  
  
  /**
   * Constructor: Creates default one deck of 52 playing cards in originalDecks and
   *          copy them to dealDecks.
   *              initialize numberDecks=n
   * Note: You need to catch MyPlayingCardException from Card constructor
   *       Use ArrayList for both originalDecks &amp; dealDecks
   */
  public Decks()
  {
      // implement this method!
  
      ArrayList&lt;Card&gt; originalDecks = new ArrayList&lt;Card&gt;(52);
      ArrayList&lt;Card&gt; dealDecks = new ArrayList&lt;Card&gt;(52); 
  
      Card card;
      for (int i=1; i&lt;=3; i++)  {
  
          for (int j=1; j&lt;= 13; j++)  {
  
              try{
                  card = new Card(j,i);   
                  }catch (MyPlayingCardException e){  
                      System.out.println("MyPlayingCardException: "+e.getMessage());
                  }
              originalDecks.add(card); 
              }               
          }
  
      dealDecks.addAll(originalDecks); 
  
  
  }
  
  /**
   * Constructor: Creates n decks (52 cards each deck) of playing cards in
   *              originalDecks and copy them to dealDecks.
   *              initialize numberDecks=n
   * Note: You need to catch MyPlayingCardException from Card constructor
   *       Use ArrayList for both originalDecks &amp; dealDecks
   */
  public Decks(int n)
  {
      int numberDecks=n ; 
      Card card; 
  
      for (int m=0; m&lt;n; m++){
  
          for (int i=0; i&lt;=3; i++) { 
  
              for (int j=0; j&lt;= 13; j++)  {
  
                  try{
                      card = new Card(j,i);      
                      }
                      catch (MyPlayingCardException e){   
                          System.out.println("MyPlayingCardException: "+e.getMessage());
                      }
                  originalDecks.add(card); 
               }
               dealDecks.addAll(originalDecks); 
          }
      }             
  
   }
  </code></pre>