I'm trying to make a deck of playing cards in Java, but when I run my code an error comes up saying java.lang.NullPointerException.
This is my code:
public class Deck
{
Card[] card= new Card[52];
Deck(){
for(int i = 0; i<13; i++){
card[i].value = i+1;
card[i].suit= "Heart";
if(card[i].value==1){
card[i].value= 11;
}
if(card[i].value==10 || card[i].value==11 || card[i].value== 12){
card[i].value = 10;
}
}
for(int i = 0; i<26; i++){
card[i+13].value = i+1;
card[i+13].suit= "Club";
if(card[i].value==1){
card[i].value= 11;
}
if(card[i].value==10 || card[i].value==11 || card[i].value== 12){
card[i].value = 10;
}
}
for(int i = 0; i<39; i++){
card[i+26].value = i+1;
card[i+26].suit= "Diamond";
if(card[i].value==1){
card[i].value= 11;
}
if(card[i].value==10 || card[i].value==11 || card[i].value== 12){
card[i].value = 10;
}
}
for(int i = 0; i<52; i++){
card[i+39].value = i+1;
card[i+39].suit= "Spade";
if(card[i].value==1){
card[i].value= 11;
}
if(card[i].value==10 || card[i].value==11 || card[i].value== 12){
card[i].value = 10;
}
}
}
}
public class Card
{
public int value;
public String suit;
Carta(){
}
}
So what i basically want, is if someone could help me see why am i getting that error?
Or how else could I make a deck of playing cards in java?