Why are you creating a class called Hand with a field called hand? That is a good way to confuse yourself.
Ana Yo wrote:. . .
Maybe because you have a constructor which leaves the List reference pointing to null, which is the default value for a field.
Ana Yo wrote:Why did I get this error . . .
Campbell Ritchie wrote:You're not going to like this, but you could simply delete the entire constructor. Or initialise the List in that constructor. But you will have to correct the other constructor too.
And that is inconsistent with the no‑args constructor. Since you can't call the constructor twice from anywhere outwith the constructor, you are stuck with having to write if (hand != null) ... everywhere hand is used. Agree with you: horrible design.
Stephan van Hulst wrote:. . . The Hand constructor that takes a Card must add the Card to the list. You can only do that if the list has been initialized. You've already done that. Now you just need to add the card to that list. . . .