ArrayList<Vector>

Discussion in 'Plugin Development' started by NoLiver92, Feb 14, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    NoLiver92

    Ho do i read the arraylist<vector> and set values to it?

    My code:
    HashMap<Integer, ArrayList<Vector>> BlockLocations;

    ArrayList<Vector> templist = new ArrayList<Vector>();
    Vector vectemp = new Vector(0,0,0);
    vectemp.setX(num);
    vectemp.setY(num);
    vectemp.setZ(num);

    templist = BlockLocations.get(num);
    templist.add(vectemp); *

    but it fails when i add it with an npe. (no i dont have the error sorry) but the error is on the line where the astrix is

    this is only a snapshot of the code
    please help
     
  2. Offline

    raGan.

    you assign arraylist to templist and then you assign null to templist. BlockLocations.get(num) is null, you have to .put(num, new ArrayList<Vector>()) there first
     
  3. Offline

    NoLiver92

    so initialize the hash map with values? before it runs?
     
  4. Offline

    mb01

    You have to put a valid list in your map before trying to use it. Here's an example:
    Code:
    List<Vector> myList = new ArrayList<Vector>();
    Map<Integer, List> myMap = new HashMap<Integer, List>();
    myMap.put(something, myList);
    Then myMap.get(something) will work, but here you don't have to call it since you already have access to the list you need. If you don't need it immediately you can do what raGan. said.
     
  5. Offline

    NoLiver92

    i have added more code before the stuff i posted earlier:

    arraylist<vector> vecarray = new arraylist<vector>();
    Vector vec = new vector(0,0,0);
    vecarray . add(0, vec);
    for(int j = 0; j<=146;j++)
    {
    if(!this.blockLocations.containskey(j))
    {
    this.blocklocations.put(j, vecarray);
    }
    }



    this code runs and it still fails in the same place as the asterix, even though this is before it
     
  6. If you want to update an existing list you need to first get the value, or you won't have more than 1 valued list per key.

    I still belive would be alot easier to just use Map<Vector, Integer>.
     
  7. Offline

    NoLiver92

    Digi
    yes but when i want to add one block at a time using a chest i would have to scan the whole map for the next integers location. the way i want to do it categorizes it by the integer which will reduce the amount of ram that i will use. as im not continuously scanning the map. (there could be up to and over 1000000 blocks)

    Im just having trouble with the array lists
     
Thread Status:
Not open for further replies.

Share This Page