1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2010
    Rep Power

    Multidimensional array of vectors?


    I'm new to Java, and I am struggling to create the following data structure. I am trying to create a 3d array of vectors. Basically I have 10 x,y,z coordinates forming a 10x10x10 grid. For each possible square I require a vector giving a list of items present in that particular square.

    So far I have this:
        protected Vector<myItems>[][][] position;
    	position[i][j][k].add(new myItems(x,y,z));
    I'm getting a null pointer exception when trying to add items to the vectors. I'm guessing this is because I haven't allocated memory for 'position' yet, but I'm struggling to do so.

    Would anyone be able to give me a hint?

  2. #2
  3. Daniel Schildsky
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Mar 2004
    KL, Malaysia.
    Rep Power

    Use ArrayList instead of Vector

    Vector is an old counterpart of ArrayList, which is a synchronised implementation. Use an ArrayList instead.

    Like any other objects, you need to instantiate an instance of ArrayList before you could add data into the instance.

    Comments on this post

    • codeJ agrees
    When the programming world turns decent, the real world will turn upside down.

IMN logo majestic logo threadwatch logo seochat tools logo