I have a problem with my Inventory

Discussion in 'Plugin Development' started by Dragonfly190, Jan 20, 2015.

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

    Dragonfly190

    Alright, well I am having problems with my Menu Plugin. Well, I keep getting Null pointer exceptions and I can't figure out why. It only happens if they click on air inside of the inventory.

    For Example, Clicking on the Feather doesn't give them an error. However, Clicking an Empty space in the Inventory throws a huge Null Pointer. Can someone help me out here is to what is causing it?

    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:302) ~[spigot.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62) ~[spigot.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:509) [spigot.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:494) [spigot.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
    at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java
    :1477) [spigot.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
    at net.minecraft.server.v1_7_R4.PacketPlayInWindowClick.a(PacketPlayInWi
    ndowClick.java:15) [spigot.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
    at net.minecraft.server.v1_7_R4.PacketPlayInWindowClick.handle(PacketPla
    yInWindowClick.java:65) [spigot.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
    at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:186
    ) [spigot.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
    at net.minecraft.server.v1_7_R4.ServerConnection.c(ServerConnection.java
    :81) [spigot.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
    at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:7
    34) [spigot.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
    at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:2
    89) [spigot.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
    at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:5
    84) [spigot.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
    at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java
    :490) [spigot.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
    at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:6
    28) [spigot.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
    Caused by: java.lang.NullPointerException
    at me.Dustin.com.Main.onInventoryClick(Main.java:82) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0
    _25]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0
    _25]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
    .8.0_25]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_25]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:298) ~[spigot.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]

    I thought it was at line 82 but then I looked at it. I dont see a problem here...

    Line 82: if (e.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.GREEN + "" + ChatColor.BOLD + "Speed")) {

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
  2. Offline

    xManfro

    Show us the main class please. Hard to help otherwise
     
  3. Offline

    87pen

    Just check if the Item is null if not, Continue.
     
  4. Like @87pen said, checking if the item is null will fix the problem. Here's what I think will fix your problem:
    Code:
    if (event.getCurrentItem().equals(null)
                    || event.getCurrentItem().getType().equals(Material.AIR)
                    || !event.getCurrentItem().hasItemMeta()) {
                player.closeInventory();
                return;
            }
    This would be under your onInventoryClick event. :)
     
    xManfro likes this.
  5. Offline

    Dragonfly190

    I dont know why I wasn't getting Alerts on this thread. Thanks anyways, you guys are Amazing!
     
  6. @Dragonfly190 No problem, anytime. Please set this thread to "Solved" under "Thread Tools". :)
     
Thread Status:
Not open for further replies.

Share This Page