Solved NullPointerException regarding inventory.

Discussion in 'Spigot Plugin Development' started by TheViperShow, 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:

    And here's the javadoc of Material getType() from ItemStack.
  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) {
    #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.