NullPointer Help

Discussion in 'Plugin Development' started by Pik0, May 31, 2014.

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

    Pik0

    I seem to get NullPointerExceptions in this piece of code. I seriously tried to fix it from many ways, but here i go:

    This is onEnable:
    Code:java
    1. for (Player player : getServer().getOnlinePlayers()) {
    2. this.players.put(player.getName(),
    3. new User(this, player.getName()));
    4. }



    And then i call this method:

    Code:java
    1. public static User getUser(Player player) {
    2. return players.containsKey(player.getName()) ? (User) players
    3. .get(player.getName()) : null;
    4. }


    And that method points a NullPointer
     
  2. Offline

    es359

    Could you post your stacktrace? Pik0
     
  3. Offline

    Pik0

    es359
    Code:java
    1. Caused by: java.lang.NullPointerException
    2. at com.piko.minigame.Main.getUser(Main.java:47) ~[?:?]
    3. at com.piko.minigame.Commands.onCommand(Commands.java:183) ~[?:?]
    4. at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[minecraft_server.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
    5. ... 13 more


    The command simply tries to get the user
     
  4. Offline

    es359

    So whats on line 47 of Main.java?
     
  5. Offline

    Pik0

    es359
    Code:java
    1. return players.containsKey(player.getName()) ? (User) players


    That line is in the getUser method
     
Thread Status:
Not open for further replies.

Share This Page