It keeps throwing this exception, but it shows up in between the output of the program that is so far operating exactly as I need it to. What could the issue be?
Alright so this is where it throws the exception: public class RunGame {
public static void main(String[] args) {
//Create players
Hand Player1 = new Hand(5);
Hand Player2 = new Hand(5);
Hand Player3 = new Hand(5);
Hand Player4 = new Hand(5);
Deck deck = new Deck();
Card print = new Card(1,'c');
deck.Shuffle();
for (int i = 0; i <= 52; i++){
print = deck.getCard(i); //**THROWS HERE**
System.out.println(print.toString());
}
And then in my Deck class there's:
public class Deck {
private char suit;
private int value;
private Card [] deck = new Card[52];
public Deck(){
int count = 0;
for(int i = 1; i <= 4; i++) {
if (i == 1)
{
suit = 'C';
}
else if (i == 2) {
suit = 'D';
}
else if (i == 3) {
suit = 'H';
}
else {
suit = 'S';
}
for (int x = 1; x <= 13; x++){
deck[count] = new Card(x, suit);
count++;
}
}
}
and
public Card getCard(int i){
int v = deck[i].getValue(); //**AND HERE**
char s = deck[i].getSuit();
Card temp = new Card(v,s);
return temp;
}
I just wanted to print the deck to make sure it was shuffling correctly. Everything prints out great but it still shows that. (My deck object is an array of 52 cards, and the getValue and getCard methods are in the Card class.)