NullPointerException

Discussion in 'Plugin Development' started by Doodledew, Jun 25, 2013.

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

    Doodledew

    How can I fix the NullPointerException here?
    Probably not that hard though. I have to check if something is a null?

    Code:
     @EventHandler
      public void egglaunch(PlayerInteractEvent e){
              Player p = (Player) e.getPlayer();
              if(!cdbomberman.contains(p.getName())){
                      if(e.getItem().getType() == Material.EGG){
                              e.setCancelled(false);
                      }
              } else {
                      if(e.getItem().getType() == Material.EGG){
                              e.setCancelled(true);
                              p.sendMessage(ChatColor.RED + "TNCkits" + ChatColor.WHITE + "> " + ChatColor.BLUE + "You can't thrown another egg yet!");
                      }
              }
      }
     
  2. Offline

    skipperguy12

    Doodledew
    You need to check if
    Code:java
    1. e.getItem()
    is null, just insert this right above where you define player:
    Code:java
    1. if(e.getItem() == null || e.getItem().getType() == Material.AIR) return;
     
  3. Offline

    Doodledew

Thread Status:
Not open for further replies.

Share This Page