Hi gang, I'm currently building a cribbage game and am running into a weird issue with 2 arrays getting mysteriously set to null. First some code, then an explanation:
snippet from GUI class:
from gameFlow class:
From Hand class:
Basically what's happening here is when the user clicks the "Deal cards" button, the actionperformed method on the GUI class gets called and creates a "gameFlow" object. The gameFlow object handles the mechanics of 1 round of cribbage. (dealing, discarding, pegging, counting, etc) In the constructor of the gameFlow class you'll see that it creates a Hand object, initializing it to a variable called "hand1."
In the constructor of the Hand class, it creates a number of different variables, including 2 Card[] arrays with a size of 6 called playerHand and compHand. These represent 2 different cribbage hands.
**Here's the problem**: Immediately after the arrays are initialized in the Hand constructor, program execution goes back to the gameFlow class. At this point the arrays somehow get set to null. Then, a bit later in the program it tries to deal
cards to populate the arrays. This throws a null pointer exception because the arrays are null - even though they were originally initialized to a size of 6.
Using JBuilder I've stepped through each line of the program and I can see the arrays getting initialized in the Hand constructor, then getting set to null once execution goes back to the gameFlow class. But I can't for the life of me figure out why. My first thought was that maybe it was the GC destroying my arrays, but you'll notice that there's another Card object created in the constructor called "upcard." This doesn't get set to null, only the 2 arrays do.
I'm guessing there's a simple explanation for what's happening, but I'm absolutely baffled. Thanks in advance for anyone who can offer some help!!
[ September 09, 2004: Message edited by: Alex McCormick ]