Hello, I am looking for some help for a class I have, I am currently getting a null pointer exception on line 10 of my Freecell.java class
Here's my code:
Freecell.java:
import java.awt.*; import javax.swing.*; import java.util.*; public class Freecell extends JApplet{ Deck a = new Deck(); public static ArrayList [] piles = new ArrayList[8]; public void init() { a = Deck.shuffle(a); for(int i = 0; i<8; i++){ piles[i].add(new ArrayList()); Pile.makePile(a, i); } repaint(); } public void paint (Graphics g){ } }
Card.java:
import java.awt.*; import javax.swing.*; import java.util.*; public class Card { public int suite; public int rank; public Card(){ suite= 0; rank=0; } public Card(int rnk, int sui){ rank = rnk; suite = sui; } public static String cardString(Card crd){ int rnk = crd.rank; int sui = crd.suite; String output = new String(); if(rnk == 2){ output = "Two"; }else if(rnk == 3){ output = "Three"; }else if(rnk == 4){ output = "Four"; }else if(rnk == 5){ output = "Five"; }else if(rnk == 6){ output = "Six"; }else if(rnk == 7){ output = "Seven"; }else if(rnk == 8){ output = "Eight"; }else if(rnk == 9){ output = "Nine"; }else if(rnk == 10){ output = "Ten"; }else if(rnk == 11){ output = "Jack"; }else if(rnk == 12){ output = "Queen"; }else if(rnk == 13){ output = "King"; }else if(rnk == 14){ output = "Ace"; }else if(rnk == 0){ output = "Zero"; }else { output = "" + rnk; } output += " of "; if(sui == 1){ output += "Diamonds"; }else if(sui == 2){ output += "Hearts"; }else if(sui == 3){ output += "Clubs"; }else if(sui == 4){ output += "Spades"; }else if(sui == 0){ output += "Nothing"; }else{ output += sui; } return output; } public static String cardFileString(Card crd){ int rnk = crd.rank; int sui = crd.suite; String output = new String(); if(rnk == 2){ output = "2"; }else if(rnk == 3){ output = "3"; }else if(rnk == 4){ output = "4"; }else if(rnk == 5){ output = "5"; }else if(rnk == 6){ output = "6"; }else if(rnk == 7){ output = "7"; }else if(rnk == 8){ output = "8"; }else if(rnk == 9){ output = "9"; }else if(rnk == 10){ output = "t"; }else if(rnk == 11){ output = "j"; }else if(rnk == 12){ output = "q"; }else if(rnk == 13){ output = "k"; }else if(rnk == 14){ output = "a"; }else if(rnk == 0){ output = "0"; }else { output = "e"; } if(sui == 1){ output += "d"; }else if(sui == 2){ output += "h"; }else if(sui == 3){ output += "c"; }else if(sui == 4){ output += "s"; }else if(sui == 0){ output += "0"; }else{ output += "e"; } output += ".gif"; return output; } public static Card getCard(int numb){ Card crd = new Card((((numb-1)%13)+2),(((numb -1)/13)+1)); return crd; } }
Deck.java:
import java.awt.*; import javax.swing.*; import java.util.*; public class Deck { public Card [] deck = new Card [52]; Deck(){ for(int i = 1; i < 53; i++){ Card crd = new Card(); crd = Card.getCard(i); deck[i - 1] = crd; } } public static Deck shuffle (Deck dk){ Deck tmp = dk; for(int i = 0; i < 100; i++){ Random r = new Random(); int rnd1 = r.nextInt(51)+1; int rnd2 = r.nextInt(51)+1; Card temp = tmp.deck[rnd1]; tmp.deck[rnd1] = tmp.deck[rnd2]; tmp.deck[rnd2] = temp; } return tmp; } }
Pile.java:
import java.awt.*; import javax.swing.*; import java.util.*; public class Pile { public static ArrayList <Card> pile = new ArrayList(); public Pile() { pile = pile; } public static void makePile (Deck dk, int num){ if(num < 1 || num > 8){ return; }else{ for(int i = 44; i%8+num > -1; i--){ Freecell.piles[num].add(dk.deck[i]); } } } }
Any help would be appreciated,
Thanks