Solved Those annoying Null pointer exceptions again!

Discussion in 'Plugin Development' started by artish1, Jul 24, 2013.

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

    artish1

    Heres the error:
    Code:
    Caused by: java.lang.NullPointerException
            at com.markyshuk.OITC.Methods.resetArena(Methods.java:172)
            at com.markyshuk.OITC.OITC.onCommand(OITC.java:213)
    
    Heres where it is.
    Code:
    ScoreboardManager manager = Bukkit.getScoreboardManager();
        if(plugin.names != null){
        for(String s : plugin.names){
            Player player = Bukkit.getPlayer(s);
           
            player.setScoreboard(manager.getNewScoreboard());  <-------- Thats da line : 172
            player.getInventory().clear();
            tpLobby(player);
            if(plugin.arenas.containsKey(s)){
            plugin.arenas.remove(s);
            }
           
        }
        }
     
  2. Offline

    kabbage

    If the player isn't online, Bukkit.getPlayer returns null. Add a null check to make sure the player is actually online.

    Code:
    if(player == null)
      continue;
    You may also want to remove the player from plugin.names entirely, unless you need it there.
     
    artish1 likes this.
  3. Offline

    artish1

    Don't you mean if player != null?
     
  4. Offline

    CubieX

    You use Bukkkit.getPlayer().
    This will return "null" if that player is currently not online.
    So add a check if player is not null, before using him.
     
    artish1 likes this.
  5. Offline

    kabbage

    No. The code checks if the player is null, and if so, continues to the next player.
     
  6. Offline

    artish1

    Well anyways thanks guys, i totally didn't know that would return null. It fixed my problem :)
     
Thread Status:
Not open for further replies.

Share This Page