Okay I promised myself that I wouldn't do this, but neither I nor my teacher can figure this out.
But when I try to get anything from the ArrayList using this in another method, it returns an error saying "Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0"
Code:
class CardDeck
{
...
public void initializeDeck()
{
ArrayList<String> temp1 = new ArrayList<String>(52);
ArrayList<Integer> temp2 = new ArrayList<Integer>(52);
int j=0; //j is rank
int k=0; //s is suit
String tempCard;
while ( true )
{
tempCard = rank[j] + "of" + suit[k];
temp1.add(tempCard);
k++;
if (k==4) { j++ ; k=0; }
if (j==13 && k==0) break;
}
for (int i=0 ; i<52 ; i++)
{
temp2.add(0);
}
setCards(temp1);
setCardCount(temp2); //same error as setCards()
}
...
public void setCards(ArrayList<String> temp)
{
currentGameCards = temp;
//debug, printing here works
for (int i=0 ; i<52 ; i++)
{
System.out.printf("\ngetCards: %d : %s", i, currentGameCards.get(i) );
}
}
...
public final String[] suit =
{"Hearts","Diamonds","Spades","Clubs"};
public final String[] rank =
{"Ace", "2", "3", "4", "5", "6" , "7" , "8" , "9" , "10" , "Jack" , "Queen" , "King"};
public ArrayList<String> currentGameCards;// = new ArrayList<String>(52)same error
public ArrayList<Integer> currentGameCardsCount;// = new ArrayList<Integer>(52) same error
Code:
for (int i=0 ; i<52 ; i++)
{
System.out.printf("\n%d : %s : %d", i, currentGameCards.get(i),currentGameCardsCount.get(i) );
}