NullPointerException

Discussion in 'Plugin Development' started by superchris05326, Nov 9, 2014.

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

    superchris05326

    When I click in the inventory but not on an item, there is a nullpointerexception on
    Code:java
    1. if(e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.BLUE + "Ice Warrior")){


    Here is the listener:
    Code:java
    1. @EventHandler
    2. public void onInventoryClick(InventoryClickEvent e){
    3. Player p = (Player) e.getWhoClicked();
    4. if(!e.getInventory().equals(inv)) return;
    5. if(e.getCurrentItem() == null) return;
    6. if(e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.BLUE + "Ice Warrior")){
    7. KitsManager.kits.put(p.getName(), KitType.ICE_WARRIOR);
    8. p.sendMessage(ChatColor.GREEN + "You have selected the Ice Warrior class!");
    9. e.setCancelled(true);
    10. p.closeInventory();
    11. }
    12. if(e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.BLUE + "Flame Rider")){
    13. KitsManager.kits.put(p.getName(), KitType.FLAME_RIDER);
    14. p.sendMessage(ChatColor.GREEN + "You have selected the Flame Rider class!");
    15. e.setCancelled(true);
    16. p.closeInventory();
    17. }
    18. }


    Does anyone know why there is an error?
     
  2. superchris05326
    Null item has no ItemMeta. You need to first check if the clicked item has ItemMeta with ItemStack#hasItemMeta().
     
  3. Offline

    Skionz

    Show us the stack-trace and tell us what line it is on.
     
Thread Status:
Not open for further replies.

Share This Page