Solved Null Pointer Exception

Discussion in 'Plugin Development' started by Xp10d3, Apr 11, 2020.

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

    Xp10d3

    Hello for some reason I get an NPE on this line: if (itemMeta.isUnbreakable() == true) { Error: https://srcb.in/4a8fce9cc2 My code works fine, but it's really bugging me. I'm not coding on Spigot/Paper; only CraftBukkit. If someone could tell me how to fix this that would be much appreciated :) Full code: https://sourceb.in/48b552447c
     
  2. Online

    KarimAKL

    @Xp10d3 'itemMeta' is null, the clicked item is probably AIR.
     
    Strahan likes this.
  3. Offline

    Strahan

    It's an InventoryClickEvent so not air but just a null (empty) slot. You should think about what things can be null when writing code. The javadocs will tell you that via the @NotNull / @Nullable annotations.
     
  4. Online

    KarimAKL

    @Strahan If the item is null, line 40 would throw a NullPointerException, but it doesn't.

    I think the only way the meta can be null is if the Material is AIR.

    But yeah, the item should be null, not AIR, in the InventoryClickEvent.
     
    Strahan likes this.
  5. Offline

    Xp10d3

    @KarimAKL @Strahan Alright thanks :) I think I fixed it. It was an issue with the material being air. Thanks for your guys's help :)
     
    KarimAKL likes this.
  6. Offline

    Strahan

    Good catch ;)
     
Thread Status:
Not open for further replies.

Share This Page