Solved NullPointerException regarding inventory.

Discussion in 'Spigot Plugin Development' started by FendiTony777, Oct 9, 2019.

  1. Ok, I'll thank everyone who answers to me.
    What my plugin is doing right here is creating an Inventory upon executing a command.
    Then I've made so it should replace 'empty' slots get replaced with glass panel. The thing is that
    I'm not understanding how can this code throw a null pointer exception when I use the
    Inventory#getItem().getType(); method.
    The code seems to give a NullPointerException. Is the issue trying to get an item slot of an inventory that isn't opened? I think not?
    Here's the code: https://paste.gg/p/anonymous/559c09afa7444a7bab7df2fef5d57dcb

    And here's the javadoc of Material getType() from ItemStack.
    upload_2019-10-9_19-23-45.png
     
  2. Can you post the error message please?
     
  3. You can't get the type if theres nothing there!

    Code (Text):
     ItemStack item = getItem(i);
                    if(item == null) {
                        //noitem
    }
     
    #4 Akkrite, Oct 9, 2019
    Last edited: Oct 9, 2019
    • Agree Agree x 1
    • Winner Winner x 1
  4. Thank you didn't realize there was a logic issue.