Nullpointer Exception at a getString function

Discussion in 'Plugin Development' started by flymia, Aug 13, 2014.

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

    flymia

    Hello Forums,

    I've got a problem with my plugin. I already wrote a command to teleport to the server lobby. This lobby is saved in the config file: [​IMG]

    At the /l command the teleport to the lobby works perfectly with this method:
    Code:java
    1. public static World getWorldFromConfig(){
    2. String lobbyStr = "tpoint.lobby.";
    3. World w = Bukkit.getWorld(plugin.getConfig().getString(lobbyStr + "world"));
    4. return w;
    5. }


    But If I do it in an event I get a nullpointer exception:
    What should It do?
    If I right click on a specific sign, it should teleport me to the lobby. Why I'm getting errors, when It works perfectly with the command?

    Please help!
     
  2. Offline

    GameplayJDK

    flymia Do you set this.plugin of the listener to your main class? Whats on line 25 in SignListener.java?
     
  3. Offline

    flymia

    Line 25 is this:
    Code:java
    1. World w = Bukkit.getWorld(plugin.getConfig().getString(lobbyStr + "world"));
    2.  


    But WHY do I get this error message. IT WORKS with the same method on the command?
     
  4. Offline

    Gerov

    flymia Are you sure that 'plugin' isn't null?
     
  5. How have you initialized plugin?
     
  6. Offline

    flymia

    Well, it should. It works on the command with this:
    Code:java
    1. AppleCraft plugin;


    It's the same on the sign function.
     
  7. Offline

    fireblast709

    yes you defined it. Have you initialized it as well?
     
    GameplayJDK likes this.
  8. Offline

    flymia

    No. Because It works on the command the same. Let me try..

    UPDATE:
    Okay, this works now. Thank you! :)
     
Thread Status:
Not open for further replies.

Share This Page