7 Replies Latest reply: May 19, 2008 3:56 PM by 807601 RSS

    array of objects giving NullPointerException

    807601
      hi

      i keep getting a NullPointerException error with this code even though i think i have the object in question initialized.

      this is the line that it says the error is on
       blockamount[x]= new Block(1,1);
      here is the actual code
      public class Group 
      {
          
         /* public static void make(int amount)
          {
              block block[]=new block[amount];
          }
         */ 
          Block blockamount[];
          public Group(int amount)
          {
             
              blockamount=new Block[amount];
             for (int x=0;x<amount;x++)
             {
                 blockamount[x]= new Block(1,1);
             }
          }
          
          int a;
          public void set()
          {
             
              for(int x=0;x<5;x++)
              {
                  
                  blockamount[x].xpos=1;
                  blockamount[x].ypos=1;
              }
              
          
          }
          
      }
      and then what run that produces the eror
      public class go 
      {
          public static void main(String []args)
          {
             Group ilike=new Group(5);
             int x=ilike.blockamount[1].xpos;
            
              
              
              
          }
      }
      thanks