Solved Getting Error in Console When Getting ItemMeta From Players Main Hand

Discussion in 'Plugin Development' started by Nick82285, Aug 11, 2017.

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

    Nick82285

    When ever I would right click an item with the name "DiamondBomb", I would get no errors, but when it is just a diamond dragged from the creative inventory it give you the error as stated below. I am sure that everything works, and everything is registered. I have been working at this for maybe a couple of hours now.

    https://pastebin.com/CFE5TJ9N
    scroll down for error and code, its all in there
     

    Attached Files:

    Last edited: Aug 11, 2017
  2. Offline

    Nick82285

    Code is in the pastebin link
     
  3. Offline

    Reflxction

    There is a NullPointerException. There is something null in line 34. Also, can you show us your entire code? That can help
     
  4. Offline

    Nick82285

    I am aware of how to read stack traces, thats why i said getting item meta in the title, but i realized where i messed up posting to pastebin, i fixed it in the new link :)
     
  5. Last edited: Aug 11, 2017
  6. Offline

    Nick82285

    Nope :/
     
  7. Online

    timtower Administrator Administrator Moderator

    @Nick82285 Please post your code using code blocks
     
  8. Offline

    Nick82285

    Yes :/ Any other suggestions?

    If they can go to the pastebin website and they have the ability to read then they should be able to diagnose my problem

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Aug 11, 2017
  9. Online

    timtower Administrator Administrator Moderator

    Then make sure that they stay valid, I had a removed page.
    No need to remove anything.

    The item can be null, check for that.
    There might be no displayname, check for that as well
     
  10. Offline

    Nick82285

    It checks to see if it is material diamond and has the metadata name of "Diamondbomb" before it spits out the item from the players inventory so its defiantly there, maybe the way im accessing the metadata is wrong? It only throws an error when i right click a normal diamond not when its named
     
  11. Online

    timtower Administrator Administrator Moderator

    @Nick82285 You are getting the itemMeta before you know the item exists.
    You are getting the name (and using it) before you know the name exists.
     
  12. Offline

    Nick82285

    https://pastebin.com/CFE5TJ9N New code that includes checking the string and it returns "DiamondBomb" when i right click a renamed one, again if i right click on a diamond from the creative inventory it returns null and its not caught. When i check to see if the string is null it still throws a null pointer exception even though im just checking to see if its null or not
     
  13. Offline

    mccrafter1212

    Are you checking to see if the item has an item meta before attempting to grab the item meta?
     
  14. Online

    timtower Administrator Administrator Moderator

    @Nick82285 player.getInventory().getItemInMainHand()
    That should be checked on null.
    the getType will throw an error already.
    And for the name, ItemMeta#hasDisplayName
     
Thread Status:
Not open for further replies.

Share This Page