Hi guys,
this is my first time posting here so please go easy on me. So I'm trying to assign a suit, number, and value for the cards for a Black Jack game for my Computer Programming class but I'm running into a problem. I have variables in my "Card.class" for all value, number, and suit but it just doesn't seem to work. It compiles fine but when I run the applet, I get an error saying something along the lines of: NullPointerException at line 64. Which is the line, "Cards[i].suit = "Spade";" . I'll appreciate any help.
// Import section // Use this section to add additional libaries for use in your program. import java.applet.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.lang.Math; // This begins the class definition. // Notice that this is a "world". You can tell since it extends Applet. public class BlackJack extends Applet implements Runnable, /*KeyListener,*/ MouseMotionListener, MouseListener { //variable declaration section // public datatype variablename public int xTitle; public int yTitle; public Card[] Cards; public int sizeC; public int randomXpos, randomYpos, randomCard; public Image cardDeck; Graphics bufferGraphics; Image offscreen; //Sets up a Thread called thread Thread thread; // Method definition section // init() is the first method an Applet runs when started public void init() { //Initialize variables xTitle=250; yTitle=50; sizeC = 52; Cards = new Card[sizeC]; /*for(int j = 0; j<13; j++) { for(int i = j; i<52; i = i+13) { Cards[i].value = j+1; Cards[i].number = j+1; } }*/ for(int i = 0; i < 13; i++) { Cards[i].suit = "Spade"; } for(int i = 13; i < 26; i++) { Cards[i].suit = "Club"; } for(int i = 26; i < 39; i++) { Cards[i].suit = "Diamond"; } for(int i = 39; i < 52; i++) { Cards[i].suit = "Heart"; } cardDeck = getImage(getDocumentBase(), "CardDeck.gif"); //double buffering offscreen = createImage(800,600); //create a new image that's the size of the applet bufferGraphics = offscreen.getGraphics(); //set bufferGraphics to the graphics of the offscreen image. setSize(800, 600); addMouseListener(this); addMouseMotionListener(this); //Set up the thread thread = new Thread(this); //constructs a new thread thread.start(); //starts the thread }//init()