I'm writing a java video poker game. When I run the test file, I get a nullpointexception error. It points to this line in my shuffling methodI'm still a novice in java...theDeck[i] = theDeck[j];
import java.util.Random; public class Deck { private Card[] theDeck; private int top; // add more instance variables if needed public Deck(){ top = 0; Card[] theDeck = new Card[52]; for(int s = 1; s <= 4; s++) { for (int v = 1; v <= 13; v++) { for (int i = 0; i < theDeck.length; i++) { theDeck[i] = new Card(s,v); } } } } public void shuffle() { // shuffle the deck here Random generator = new Random(); int i; int j; i = generator.nextInt(51) + 1; j = generator.nextInt(51) + 1; Card temp = theDeck[i]; for(int k = 1; k <100; k++) { theDeck[i] = theDeck[j]; theDeck[j] = temp; } top = 0; }
this is the part of the class that calls the shuffle method:
public void play() { cards.shuffle(); for( int i =1; i <= 5; i++) { p.addCard(cards.deal()); cards.incrementTop(); } for( int j = 1; j < 5; j++) { p.getHand().get(j).toString(); } System.out.println("These are your cards:"); for( Card c : p.getHand()) {