[SOLVED]NullPointerException after Location.add??

Discussion in 'Plugin Development' started by Bjornke, Jul 16, 2012.

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

    Bjornke

    So here is the problem: a user clicks a block to add as a spawn, then that location is sent to the addSpawn method to be added to active HashMap for game and saved to config, but if I try to use the .add on the location, I get a NPE on the next line that takes the location and adds it to the HashMap?

    Code:Java
    1.  
    2. public void addSpawn(Location spawnblock, int wavenumber, String map) {
    3. spawnblock.add(0.5, 1, 0.5);
    4. spawnPoints.get(map).put(spawnblock, wavenumber); //NPE Here
    5. List<String> aspawn = new ArrayList<String>();
    6. for(Location spawnloc : spawnPoints.get(map).keySet()) {
    7. aspawn.add(parseToDoorStr(spawnloc, spawnPoints.get(map).get(spawnloc)));
    8. }
    9. this.getConfig().set(world.getName() + "." + map + ".zombiespawns", aspawn);
    10. this.saveConfig();
    11. }

    And to be clear, everything works fine if I don't use the .add on the location.
    Any reason as to why??

    Well, the fix for it was simply adding to the location and then creating a "temploc" from the added location..

    Code:Java
    1. spawnblock.add(0.5, 1, 0.5);
    2. Location temploc = spawnloc
    3. spawnPoints.get(map).put(spawnblock, wavenumber);


    Strange as it is, this is completely ridiculous...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  2. Offline

    Bavestry

    If the problem has been solved, edit your thread to say [Solved] in the front. Don't simply delete it, let others learn from your 'mistakes'.
     
Thread Status:
Not open for further replies.

Share This Page