Solved getWorld() creates a NullPointerException?

Discussion in 'Plugin Development' started by Quidam, Jan 24, 2013.

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

    Quidam

    Please help ASAP, I'd appreciate it very much.

    In my plugin, I set a location with this:
    Code:
    public Location loc;
    Later on in the code, I set the world and coordinates:

    Code:
    loc.setWorld(Bukkit.getServer().getWorld("shop"));
    loc.setX(xco);
    loc.setY(yco);
    loc.setZ(zco);
    Upon using the command, the console returns with a NullPointerException at line 36 of my CommandExecutor. Line 36 is this:
    Code:
    loc.setWorld(Bukkit.getServer().getWorld("shop"));
    Thanks in advance.
     
  2. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    loc is null, you haven't set it to any instance.
     
  3. Offline

    Quidam

    How do I enable it, then? I need to teleport the player to the coded world and coordinates.
     
  4. Offline

    raGan.

    Instantiate it ?
     
  5. Offline

    Quidam

    Initialize it.
     
  6. Offline

    ryanbai

    mbaxter could you please sort out the plugins on my server??
    if so contact me on skype please asap
    Skype: chrisanderson16
     
  7. Offline

    Johnzeh

    World loc = Bukkit.getServer().getWorld("shop");
     
  8. Offline

    evilmidget38

    Are you serious?
     
    Quidam likes this.
  9. Offline

    Quidam

    What is the point of this code? That sets a variable for the world... It is literally the exact same code.
     
  10. Offline

    evilmidget38

    Actually worse, because he's defining a local variable of type World with the same name as your Location variable.
    Anyways, you're never assigning a value to loc. Instantiate a location(new Location) or assign the location based on an event. I'm not going to spoon-feed you code, so if you don't understand that, refer to a java textbook.
     
  11. Offline

    Quidam

    Oh, I feel dumb. Instantiate. Okay, thanks. That answer was posted up above but I failed to realize what that meant >_< Grr. Well thank you very much :3
     
Thread Status:
Not open for further replies.

Share This Page