Bear Bibeault wrote:OK, so think about what your next debugging step could be. What terms in that statement are subject to NPE's? One strong suspect is p2 (p2? Surely you can think of better names for things!).
How can you find out what's null, but shouldn't be?
I'm unsure. To be honest I haven't gone to school and don't have any background in programming so everything is new to me and I'm kind of "faking it till I make it"
That said, what I can say about that line is that my intention with it is to check that p1Play (the entered int) is equal to any card in Player Two's hand array. && If that's satisfied, then cardUsed must be false (otherwise a player could keep asking for the same King of Hearts over and over), and finally, since the Player Two hand array has certain null indices, it makes sure to disregard those.
That's what I intend with that "if logic" but maybe I could be misunderstanding my own code
My hunch is that there's something wrong with my dealHands method, but I can't be sure and don't know how to use eclipse to isolate the problem(again, I'm new) To be more specific, I'm thinking perhaps the dealHands method is actually not creating references in the hand arrays as I intend them to due to erroneous code.
James Boswell wrote:Justin
From a quick review of your code, it looks like you have not initialised your hand array for the p2 variable (instance of PlayerTwo). Simply setting it to
does not assign any objects to the array.
If you mean the hand arrays in classes PlayerOne and PlayerTwo, the dealHands method in class Card is intended to fill indices 0-7 with references to
cards in Card.deck[] Here is the excerpt
(basically fill the array with card references rather than card objects...however un-proper that may be, again, I have a very limited toolset and understanding about how to achieve what I want to achieve when writing a program. I initially tried to actually take the objects themselves out of the deck array in class Card and place them in the hand arrays in classes PlayerOne and PlayerTwo, but then I was unsure if it would be wise to do that, since it would make null indices in deck[], thus requiring even more null-checking all throughout the program)