Solved Null Pointer exception

Discussion in 'Plugin Development' started by pingpong1999, Apr 24, 2016.

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

    pingpong1999

    Hey guys I am trying to open up an inventory but there is a null pointer exception that I dont exactly know how to fix:

    Code:
               ItemStack CurrentPick = new ItemStack (Material.DIAMOND_PICKAXE);
                    ItemMeta CurrentPickMeta = CurrentPick.getItemMeta();
                 
                 
                    ItemStack item = player.getItemInHand();
                    ItemMeta itemMeta = item.getItemMeta();
                    itemMeta.setDisplayName(CurrentPickMeta.getDisplayName());
                    //Map<Enchantment, Integer> Enchants = player.getInventory().getItemInHand().getEnchantments();
                 
                    List<String> lore = new ArrayList<String>();
                    List<String> loreCurrent = new ArrayList<String>();
                    if(itemMeta.hasLore()){
                        List<String> oldLore = itemMeta.getLore();
                        lore.addAll(oldLore);
    
                }
    
                    CurrentPick.setItemMeta(itemMeta);
    
    I'm trying to copy the meta data from the pick in the player's hand to the one in the inventory. It works if have only enchantments, or only Lore without enchantments. But if I have a mix of both two then it does not open the gui and throws a null pointer exception
    -edit if anyone knows, how do I refresh the inventory on a click?
     
  2. Offline

    teej107

    @pingpong1999 Read up on the JavaDocs for the methods you are using. They could return null or not.
     
  3. Offline

    pingpong1999

    Thankyou! fixed the issue :)
     
Thread Status:
Not open for further replies.

Share This Page