0
 if(tempCard.getSuitValue() == PlayingCard.CLUBS || tempCard.getSuitValue() == PlayingCard.SPADES)

this is the line that is giving me a NullPointerException

PlayingCard redCard, blackCard, tempCard; 

tempCard is declared as a varible of object PlayingCard

public PlayingCard(int newFace, int newSuit)
{
    faceValue = newFace; 
    suitValue = newSuit; 
}

this is the constructor for object PlayingCard, as well as the parameters for it

public int getFaceValue()
{
    return faceValue;
}
public int getSuitValue()
{
    return suitValue; 
}

these methods give values to the getSuitValue method used in the statement at the very top

public final static int CLUBS = 0;
public final static int DIAMONDS = 1;
public final static int HEARTS = 2; 
public final static int SPADES = 3;

these are the constant values for the cards in the deck.

I have gone through every method and constructor that is used in the line that results in the NullPointerException. If anyone wants to see all 4 classes, I can post them at their request.

J. Backer
  • 1
  • 1
  • 1
    I think only possibility is `tempCard` is null. Please debug and check whether `tempCard` is null or not. – akash Dec 10 '15 at 06:22
  • 'tempCard' is obviously 'null'. So do something about it. – Tom Dec 10 '15 at 06:22
  • @Tom maybe the NPE comes from an Integer unboxing because of == –  Dec 10 '15 at 06:25
  • @RC. Both sides work with the primitive 'int' so where should that 'Integer' come from? – Tom Dec 10 '15 at 06:27
  • `return suitValue;` <= this might be an "Integer" (@Grogi we don't see the whole class..) –  Dec 10 '15 at 06:29
  • 1
    @RC In the constructor it is initialized from an `int`. No, it cannot be `null` - unless the OP really really wants it to be... – Grogi Dec 10 '15 at 06:30
  • @RC. Then the part "because of ==" would still be incorrect ;P. But this would also mean that Op doesn't use this mentioned constructor and I don't think that Op even know that 'Integer' exists, because he might be a beginner. – Tom Dec 10 '15 at 06:36
  • Have you initialized created new instance with new operator on tempCard? make sure it is done.... – usman Dec 10 '15 at 07:01

0 Answers0