I am trying to add an item to a list of card objects, and I get a nullpointer exception if I run this code. I believe I can't add to a 'null' list, but how do I fix this? (The error occurs at 'cards.add(...);')
public class Deck {
private List<Card> cards;
public Deck(String[] ranks, String[] suits, int[] values) {
for (int i = 0; i < ranks.length; i++) {
for (int j = 0; j < suits.length; j++){
cards.add(new Card(ranks[i], suits[j], values[i]));
}
}
}