PlayerInteractEvent#getItem()#hasItemMeta returns null

Discussion in 'Plugin Development' started by MrDaniel, Mar 27, 2019.

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

    MrDaniel

    Code:
    ItemMeta meta = item.getItemMeta();
    Returns null pointer exception.
     
  2. Offline

    timtower Ninja on the waves Moderator

    @MrDaniel Did you check if there even is an item?
     
  3. Offline

    MrDaniel

    @timtower, I didn't check but I did it with an item and without and same error. item#hasItemMeta also returns null
     
  4. Offline

    KarimAKL

    @MrDaniel If 'item.hasItemMeta()' throws a NullPointerException then 'item' is null. (could be an empty slot in the inventory or an ItemStack that hasn't been initialized yet)
     
  5. Offline

    MrDaniel

    @KarimAKL but even if he has an item in his hand it returns null.
     
  6. Offline

    timtower Ninja on the waves Moderator

    Then what is the value of item? Print it to the console.
    What is item? Where does it get assigned?
     
  7. Offline

    Robnoo

    Can you paste the full method you wrote?
    Invoking any method on a null reference will throw a nullpointer exception. It's better to check if(item == null).
    Where is 'item' declared?
     
  8. Offline

    MrDaniel

    @Robnoo, please don't respond unless you have a solution that wasn't proposed before
     
  9. Offline

    timtower Ninja on the waves Moderator

    Has this been solved or not?
    If so: please mark it as so.
    If not: please provide us with more code.
     
Thread Status:
Not open for further replies.

Share This Page