Solved Throwing a NPE and a bunch of other errors

Discussion in 'Plugin Development' started by Prothean_IGS, Feb 3, 2014.

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

    Prothean_IGS

    Alright so I have a ItemClickEvent in one of my class for a plugin I am currently working on, and while it works perfectly fine on the items I want it to, it throws a NPE and some other errors whenever a player clicks on an item that isn't part of my code. I have a return false statement for if it's not the item I want, but that didn't seem to do anything. I just don't want there to be errors every time a player clicks an item.

    Here's the errors I get in console: http://pastebin.com/t16vkskP

    And here is my entire class that includes the itemClickEvent(I know it's long, and I only posted the whole thing so that the errors would match up correctly): http://pastebin.com/kvcf2sf8
     
  2. Offline

    sgavster

    @Prothean_IGS add if(event.getCurrentItem() != null && event.getCurrentItem().getType() != null) { //your code }​
     
  3. Offline

    Prothean_IGS

    sgavster Where should I be adding that? And it doesn't just happen when the player clicks with nothing in their hand, it happens anytime the item doesn't contain the lores that are coded in to be checked for
     
  4. Offline

    sgavster

  5. Offline

    Prothean_IGS

    sgavster There is no event.getCurrentItem(). It's actually a PlayerInteractEvent, sorry. Anyone know how I can fix the error's from happening when a player clicks on an item that doesn't have the specific lore?
     
  6. Offline

    sgavster

    Prothean_IGS
    Code:java
    1. ItemStack i = player.getItemInHand();
    2. if(i.hasItemMeta() && i.getItemMeta().hasDisplayName()) {
    3. }
     
  7. Offline

    Prothean_IGS

    Solved, thank you.
     
  8. Offline

    random_username

Thread Status:
Not open for further replies.

Share This Page