Hi, working on a poker program(isn't everybody?) After searching for hours on the web I'm hoping someone here can help me. Here is the problematic snippet below.
// this part works fine for (Player player : players){ player = new Player(); player.pocketCard1 = new Card(deck.deal()); System.out.print(player.pocketCard1.toString() + " "); player.pocketCard2 = new Card(deck.deal()); System.out.print(player.pocketCard2.toString() + " "); } // this part throws a null pointer exception System.out.print(players[0].pocketCard1.toString() + " ");
It seems like the assignments I made to pocketCard1 simply disappear when the for loop ends. Can I not use a for loop to set data members? The second piece of code does exactly the same thing as the first.
I'm pulling my hair out here.
-dean_martin