3 Replies Latest reply: Feb 20, 2007 10:24 AM by 807606 RSS

    Help!! Exception in thread "main" java.lang.NullPointerException

    807606
      Hi i'm new to java and was wondering what this exception means? heres my code..



      /**
      * @(#)setGame.java
      *
      *
      * @author
      * @version 1.00 2007/2/20
      */
      import java.io.*;



      class card{
           private String number;
           private String shape;
           private String colour;
           private String shading;
           
                
           public void setShading(String shde){
                
                if(shde.equals("filled")||shde.equals("striped")||shde.equals("empty") ){
                     shading = shde;
                }
                else{
                     System.out.println("error shading property does not compute.");
                }
           }
           
           public void setColour(String colr){
                
                if(colr.equals("red")||colr.equals("green")||colr.equals("purple")){
                     colour = colr;
                }
                else{
                     System.out.println("error colour property does not compute.");
                }
           }
           
           public void setShape(String shp){
                
                if(shp.equals("round")||shp.equals("diamond")||shp.equals("squiggly")){
                     shape = shp;
                }
                else{
                     System.out.println("error shape property does not compute.");
                }
                
           }
           
           public void setNumber(String num){
                
                if(num.equals("1")||num.equals("2")||num.equals("3")){
                     number = num;
                }
                else{
                     System.out.println("error shape property does not compute.");
                }
                     
           }
           
           public void DisplayCard(){
                System.out.print(number + " ");
                System.out.print(shape + " ");
                System.out.print(colour + " ");
                System.out.print(shading + " ");
                System.out.println("------------------");
           }
      }

      class deck{
           
      }

      public class setGame {

      /**
      * Creates a new instance of <code>setGame</code>.
      */
      public setGame() {
      }

      /**
      * @param args the command line arguments
      */
      public static void main(String[] args) {

      card [] cardDeck = new card[81];
      // TODO code application logic here


      System.out.println("Welcome to Set game!.");

      //Creating the shading, shape, and colour properties
      //for the 81 cards and storing them into an array.


      for(int i=0;i<81;i++){
           
           if(i/27==0){
                cardDeck.setShading("filled");
                if(i/9==0){
                     cardDeck[i].setShape("round");
                     if(i/3==0){
                          cardDeck[i].setColour("red");
                     }
                     else if(i/3==1){
                          cardDeck[i].setColour("green");
                     }
                     else if(i/3==2){
                          cardDeck[i].setColour("purple");
                     }
                }
                else if(i/9==1){
                     cardDeck[i].setShape("diamond");
                     if(i/3==0){
                          cardDeck[i].setColour("red");
                     }
                     else if(i/3==1){
                          cardDeck[i].setColour("green");
                     }
                     else if(i/3==2){
                          cardDeck[i].setColour("purple");
                     }
                }
                else if(i/9==2){
                     cardDeck[i].setShape("squiggly");
                     if(i/3==0){
                          cardDeck[i].setColour("red");
                     }
                     else if(i/3==1){
                          cardDeck[i].setColour("green");
                     }
                     else if(i/3==2){
                          cardDeck[i].setColour("purple");
                     }
                }     
           }
           
           else if(i/27==1){
                cardDeck[i].setShading("striped");
                if(i/9==0){
                     cardDeck[i].setShape("round");
                     if(i/3==0){
                          cardDeck[i].setColour("red");
                     }
                     else if(i/3==1){
                          cardDeck[i].setColour("green");
                     }
                     else if(i/3==2){
                          cardDeck[i].setColour("purple");
                     }
                }
                else if(i/9==1){
                     cardDeck[i].setShape("diamond");
                     if(i/3==0){
                          cardDeck[i].setColour("red");
                     }
                     else if(i/3==1){
                          cardDeck[i].setColour("green");
                     }
                     else if(i/3==2){
                          cardDeck[i].setColour("purple");
                     }
                }
                else if(i/9==2){
                     cardDeck[i].setShape("squiggly");
                     if(i/3==0){
                          cardDeck[i].setColour("red");
                     }
                     else if(i/3==1){
                          cardDeck[i].setColour("green");
                     }
                     else if(i/3==2){
                          cardDeck[i].setColour("purple");
                     }
                }
                
           }
           else if(i/27==2){
                cardDeck[i].setShading("empty");
                if(i/9==0){
                     cardDeck[i].setShading("round");
                     if(i/3==0){
                          cardDeck[i].setColour("red");
                     }
                     else if(i/3==1){
                          cardDeck[i].setColour("green");
                     }
                     else if(i/3==2){
                          cardDeck[i].setColour("purple");
                     }
                }
                else if(i/9==1){
                     cardDeck[i].setShading("diamond");
                     if(i/3==0){
                          cardDeck[i].setColour("red");
                     }
                     else if(i/3==1){
                          cardDeck[i].setColour("green");
                     }
                     else if(i/3==2){
                          cardDeck[i].setColour("purple");
                     }
                }
                else if(i/9==2){
                     cardDeck[i].setShading("squiggly");
                     if(i/3==0){
                          cardDeck[i].setColour("red");
                     }
                     else if(i/3==1){
                          cardDeck[i].setColour("green");
                     }
                     else if(i/3==2){
                          cardDeck[i].setColour("purple");
                     }
                }
           }
      }

      //Creating the Number property for the 81 cards
      //and storing them into an array.

      for(int i=0;i<81;i=i+3){
           cardDeck[i].setNumber("1");
      }
           
           for(int i=1;i<81;i=i+3){
           cardDeck[i].setNumber("2");
      }     

      for(int i=2;i<81;i=i+3){
           cardDeck[i].setNumber("3");
      }

      for(int i=0;i<81;i++)
           cardDeck[i].DisplayCard();
      }
      }