Solved HashMap problems

Discussion in 'Plugin Development' started by Assist, Aug 28, 2013.

Thread Status:
Not open for further replies.
  1. It seems like I've been posting stuff about hashmaps quite alot, but anyways,
    Code:
    this.playerCount.put(id, 1);
    int count = this.playerCount.get(id);
     
    System.out.println(count);
    It prints out "1", which is correct. It continues through my code, and reads this
    Code:
    SignWall wall = new SignWall(clazz);
    wall.updateSigns(id);
    Works fine, it updates my signs.. but one thing doesn't work,
    Code:
    if (map.playerCount.get(id) > 0) { // NullPointerException
        int size = map.playerCount.get(id);
        lines[3] = size + "/9";
        System.out.println(size + " - 4");
        System.out.println(lines[3] + " - 5");
    } else {
        lines[3] = "0/9";
    }
    I for the life of me can't figure out why this particular part of all what I've done above, doesn't work. I'm guessing that there is no key "id" in the playerCount hashmap.. but the thing is, I just put the key in there - the key is correct, since I use it in some of the code above that part.

    If you need more code, just ask, though this is all the relevant.
     
  2. Offline

    Rocoty

    Just pastebin the whole class, makes it easier for us to debug for you. There is more code relevant to your problem than you think.
     
  3. Offline

    adam753

    The "map" variable may be null. If it's meant to be a reference to another class instance in your plugin, you may have just forgotten to set it.
     
  4. Offline

    Qwertyness_

    It looks as if the "map" is referencing another class in your plugin. Are you sure you defining the hashmap in both classes?
     
  5. Offline

    xTrollxDudex

    Assist
    Either you need to make it static or make a getter/setter for it.
     
  6. That fixed it, thanks! :D
     
Thread Status:
Not open for further replies.

Share This Page