So I'm trying to make a program that shuffles cards by storing their information and randomly moving them. All the information and programming is set and it compiles, however whenever I try to load the array, I get a java.lang.NullPointerException. I've been trying to figure out what the problem is but I need some help
This is the World
this is the Cards itself
any help would be greatly appreciated
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class CardWorld here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class CardWorld extends World
{
/**
* Constructor for objects of class CardWorld.
*
*/
public CardWorld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
}
Cards[] thisDeck;
/**
* Act - do whatever the Cards wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if (Greenfoot.isKeyDown("l"))loadDeck(thisDeck);
if (Greenfoot.isKeyDown("s"))showCards(thisDeck);
}
public void loadDeck(Cards[] thisDeck)
{
String cardName;
GreenfootImage cardPic;
int suit;
int cardVal;
int cardRank;
Cards thisCard;
for (int suitCount = 0; suitCount <=3; suitCount++)
{
for (int count = 101; count <= 113; count++)
{
cardName = (suitCount)*13 + count + ".gif";
cardPic = new GreenfootImage(cardName);
suit = suitCount;
cardRank = count -100;
if (cardRank == 1) cardRank = 14;
if (count < 111)
{
cardVal = count -100;
}
else
{
cardVal = 10;
}
int index = (count -100)+ 13*(suitCount);
thisCard = new Cards(cardPic, suit, cardVal, cardRank, index);
thisDeck[index] = thisCard;
}
}
}
public void showCards(Cards[] thisDeck)
{
Cards thisCard;
int index;
//GreenfootImage thisImage;
for (int suit = 0; suit <=3; suit++)
{
for (int counter = 1; counter <= 13; counter++)
{
index = counter + suit * 13;
thisCard = thisDeck[index];
addObject(thisCard, 50 + counter*20, 50+50*suit); //space out the cards on the screen
}
}
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Cards here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Cards extends Actor
{
public GreenfootImage cardFace;
public int suit;
public int faceValue;
public int cardRank;
public int index;
public Cards(GreenfootImage parFace, int parSuit, int parValue, int parRank, int parIndex)
{
cardFace = parFace;
setImage(cardFace);
suit = parSuit;
faceValue = parValue;
cardRank = parRank;
index = parIndex;
}
/**
* Act - do whatever the Cards wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
}
}

