Sunday, April 19, 2015

Implementing a card game in JAVA - Help with deck


I have jsut simplified the construtor to jsut print the value of masterPack[0].

I get an exception, the problem is masterPack is not accepted in the Construtor.. i dont know why?


public Dec(int val)

{

allocateMasterPack();

System.out.println("Printing the values in constructor");

cards = new Card[52];

for (int k = 0; k < cards.length; k++)

cards[k]= new Card();

System.out.println ( masterPack[0]);

// init(val);


}


Output:

======

allocateMasterPack() activated

Construting the masterPAck

Value at index 8 is9 of Clubs

Printing the values now

Value at index 0 isA of Clubs


Printing the values now

Value at index 1 is2 of Clubs


Exception in thread "main" Printing the values now

Value at index 2 is3 of Clubs


Printing the values now

Value at index 3 is4 of Clubs


Printing the values now

Value at index 4 is5 of Clubs


Printing the values now

Value at index 5 is6 of Clubs


Printing the values now

Value at index 6 is7 of Clubs


Printing the values now

Value at index 7 is8 of Clubs


Printing the values now

Value at index 8 is9 of Clubs


Printing the values now

Value at index 9 isT of Clubs


Printing the values now

Value at index 10 isJ of Clubs


Printing the values now

Value at index 11 isQ of Clubs


Printing the values now

Value at index 12 isK of Clubs


Printing the values now

Value at index 13 isA of diamonds


Printing the values now

Value at index 14 is2 of diamonds


Printing the values now

Value at index 15 is3 of diamonds


Printing the values now

Value at index 16 is4 of diamonds


Printing the values now

Value at index 17 is5 of diamonds


Printing the values now

Value at index 18 is6 of diamonds


Printing the values now

Value at index 19 is7 of diamonds


Printing the values now

Value at index 20 is8 of diamonds


Printing the values now

Value at index 21 is9 of diamonds


Printing the values now

Value at index 22 isT of diamonds


Printing the values now

Value at index 23 isJ of diamonds


Printing the values now

Value at index 24 isQ of diamonds


Printing the values now

Value at index 25 isK of diamonds


Printing the values now

Value at index 26 isA of Hearts


Printing the values now

Value at index 27 is2 of Hearts


Printing the values now

Value at index 28 is3 of Hearts


Printing the values now

Value at index 29 is4 of Hearts


Printing the values now

Value at index 30 is5 of Hearts


Printing the values now

Value at index 31 is6 of Hearts


Printing the values now

Value at index 32 is7 of Hearts


Printing the values now

Value at index 33 is8 of Hearts


Printing the values now

Value at index 34 is9 of Hearts


Printing the values now

Value at index 35 isT of Hearts


Printing the values now

Value at index 36 isJ of Hearts


Printing the values now

Value at index 37 isQ of Hearts


Printing the values now

Value at index 38 isK of Hearts


Printing the values now

Value at index 39 isA of Spades


Printing the values now

Value at index 40 is2 of Spades


Printing the values now

Value at index 41 is3 of Spades


Printing the values now

Value at index 42 is4 of Spades


Printing the values now

Value at index 43 is5 of Spades


Printing the values now

Value at index 44 is6 of Spades


Printing the values now

Value at index 45 is7 of Spades


Printing the values now

Value at index 46 is8 of Spades


Printing the values now

Value at index 47 is9 of Spades


Printing the values now

Value at index 48 isT of Spades


Printing the values now

Value at index 49 isJ of Spades


Printing the values now

Value at index 50 isQ of Spades


Printing the values now

Value at index 51 isK of Spades


Printing the values in constructor

java.lang.NullPointerException

at Dec.<init>(debug.java:195)

at debug.main(debug.java:7)



No comments:

Post a Comment