NullPointerException

Discussion in 'Plugin Development' started by MgMaor, Apr 4, 2014.

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

    MgMaor

    Why does it throw NullPointerExceptions when I use it?
    VV
    public static boolean playerExists(String playerName) {
    return plugin.getConfig().contains(playerName);
    }
    I checked:
    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
    Broadcasts.joinBroadcast(event);
    if (!Tools.playerExists(event.getPlayer().getName())) {
    Economy.addPlayer(event.getPlayer().getName());
    }
    }

    And got big NullPointerException.
    Why does it happen?
     
  2. Offline

    Zethariel

    Because playerExists can return a null (not found in the config) instead of a boolean false
     
  3. Offline

    skyrimfan1

    Instead try:
    Code:java
    1. public static boolean playerExists(String playerName) {
    2. return plugin.getConfig().contains(playerName) != null;
    3. }
     
Thread Status:
Not open for further replies.

Share This Page