NullPointerException?

Discussion in 'Plugin Development' started by Croug, Sep 20, 2013.

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

    Croug

    I have no idea why this code is throwing me a null pointer, it's at line 18, please help!

    -Croug

    Code:java
    1. package com.CalcuProcessing.SuperMeatBoy;
    2.  
    3. import org.bukkit.Location;
    4. import org.bukkit.World;
    5.  
    6. public class WorldMap {
    7. private Location Start, End;
    8. public WorldMap(Location Start, Location End){
    9. this.Start = Start;
    10. this.End = End;
    11. sort();
    12. }
    13.  
    14. private void sort(){
    15. double bufx;
    16. double bufy;
    17. double bufz;
    18. if(Start.getX() > End.getX()){
    19. bufx = End.getX();
    20. End.setX(Start.getX());
    21. Start.setX(bufx);
    22. }
    23. if(Start.getY() > End.getY()){
    24. bufy = End.getY();
    25. End.setY(Start.getY());
    26. Start.setY(bufy);
    27. }
    28. if(Start.getZ() > End.getZ()){
    29. bufz = End.getZ();
    30. End.setZ(Start.getZ());
    31. Start.setX(bufz);
    32. }
    33. }
    34.  
    35. public boolean Contains(Location loc){
    36. if(loc.getX() > Start.getX() &&
    37. loc.getY() > Start.getY() &&
    38. loc.getZ() > Start.getZ() &&
    39. loc.getX() < End.getX() &&
    40. loc.getY() < End.getY() &&
    41. loc.getZ() < End.getZ()){
    42. return true;
    43. }
    44. return false;
    45. }
    46. }
    47.  
     
  2. Offline

    The_Doctor_123

    Your Locations need to be initialized.

    Location constructor:

    Code:java
    1. Location location = new Location(world, x, y, z);
     
  3. Offline

    Croug


    They are, in the class constructor

    Code:java
    1. this.Start = Start;
    2. this.End = End;
     
  4. Offline

    The_Doctor_123

    Croug
    Oh, sorry about that. XD

    But now I must ask, are the two Locations provided null?
     
  5. Offline

    Croug

    hmm, i don't think so, but now that i think about it, i never checked to make sure my player listener was listener.

    Solved it, i forgot to initialize my player listener class haha.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
Thread Status:
Not open for further replies.

Share This Page