NullPointerException ._.

Discussion in 'Plugin Development' started by rockers3000, Jul 16, 2015.

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


    Well, I've been a little stuck on this and I'm not aware of a way to fix it. But then again, I'm new to Bukkit.

    //Player clicked bottom block
                            int id = Integer.parseInt(player.getItemInHand().getItemMeta().getLore().get(1));
                            ArrayList<Location> listLocation = new ArrayList<Location>();
                                listLocation = jailDoorIDHash.get(id);
                            catch(IndexOutOfBoundsException e){}
                            jailDoorIDHash.put(id, listLocation);
    This basically gets a HashMap<int, ArrayList<Location>> and gets its value (ArrayList<Location>) based off of player.getItemInHand().getItemMeta().getLore().get(1) parsed. Up to there, it works (seemingly). However, when it reads listLocation.add(b.getLocation()), I get a NullPointerException...

    [01:50:01] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to JailbreakPlugin v1.0
        at$1.execute( ~[craftbukkit-1.8.7-R0.1-SNAPSHOT-remapped.jar:git-Bukkit-bf4818b]
        at org.bukkit.plugin.RegisteredListener.callEvent( ~[craftbukkit-1.8.7-R0.1-SNAPSHOT-remapped.jar:git-Bukkit-bf4818b]
        at org.bukkit.plugin.SimplePluginManager.fireEvent( [craftbukkit-1.8.7-R0.1-SNAPSHOT-remapped.jar:git-Bukkit-bf4818b]
        at org.bukkit.plugin.SimplePluginManager.callEvent( [craftbukkit-1.8.7-R0.1-SNAPSHOT-remapped.jar:git-Bukkit-bf4818b]
        at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInteractEvent( [craftbukkit-1.8.7-R0.1-SNAPSHOT-remapped.jar:git-Bukkit-bf4818b]
        at net.minecraft.server.v1_8_R3.PlayerInteractManager.interact( [craftbukkit-1.8.7-R0.1-SNAPSHOT-remapped.jar:git-Bukkit-bf4818b]
        at net.minecraft.server.v1_8_R3.PlayerConnection.a( [craftbukkit-1.8.7-R0.1-SNAPSHOT-remapped.jar:git-Bukkit-bf4818b]
        at net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace.a( [craftbukkit-1.8.7-R0.1-SNAPSHOT-remapped.jar:git-Bukkit-bf4818b]
        at net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace.a( [craftbukkit-1.8.7-R0.1-SNAPSHOT-remapped.jar:git-Bukkit-bf4818b]
        at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$ [craftbukkit-1.8.7-R0.1-SNAPSHOT-remapped.jar:git-Bukkit-bf4818b]
        at java.util.concurrent.Executors$ Source) [?:1.8.0_31]
        at Source) [?:1.8.0_31]
        at net.minecraft.server.v1_8_R3.SystemUtils.a( [craftbukkit-1.8.7-R0.1-SNAPSHOT-remapped.jar:git-Bukkit-bf4818b]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B( [craftbukkit-1.8.7-R0.1-SNAPSHOT-remapped.jar:git-Bukkit-bf4818b]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B( [craftbukkit-1.8.7-R0.1-SNAPSHOT-remapped.jar:git-Bukkit-bf4818b]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A( [craftbukkit-1.8.7-R0.1-SNAPSHOT-remapped.jar:git-Bukkit-bf4818b]
        at [craftbukkit-1.8.7-R0.1-SNAPSHOT-remapped.jar:git-Bukkit-bf4818b]
        at Source) [?:1.8.0_31]
    Caused by: java.lang.NullPointerException
        at me.LyesDoesPlugins.jailbreakPlugin.jailbreakMain.onPlayerUse( ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_31]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_31]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_31]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_31]
        at$1.execute( ~[craftbukkit-1.8.7-R0.1-SNAPSHOT-remapped.jar:git-Bukkit-bf4818b]
        ... 17 more
    Could someone help?
  2. Offline


    The problem is b is null. But I have no idea what b is, where it is initialized, or how it is mutated throughout its lifecycle. I cannot solve your problem without this information.

    Also, I have no idea why you are using a try/catch block in that function. Can't you just check if jailDoorIDHash contains id?
  3. Offline


    Sorry, I forgot to mention that b is a Block. I have also tried it with other locations, however, and have still gotten the same error. I also was using the try-catch mostly for debugging, but I don't think thats what gave me the error. I could be wrong, but I don't think thats the problem. (Im not on my PC at the moment so I cant check.)
  4. Offline


    I really can't tell what you're doing exactly, but you should check if the item has item meta before getting the lore.
  5. Offline


    Before all of this, it checks to see if the player is holding a specific tool with a specific lore set at lore(0). When you get the tool, you then must set an ID which gets set to lore(1). When you right click with this tool on an iron door, it should add the iron door's bottom block postion to the jailDoorIDHash value with the key being the tool ID (lore1). Example:

    Player types command to get tool. (with args [0] being the ID)

    Player recieves special tool (With lore0 being set to "JailDoorWandTool" or something and lore1 being set to args [0], The ID)

    Player clicks iron door.
    This *should* add the bottom blocks location to a Location-ArrayList within the HashMap based off of the tool's ID (lore1).

    It is all working up till

    Tommorow, I will try to post the code, if you can't figure it out.
    (Its 3.30 AM where I live.)
  6. Offline


    Shortninja66 likes this.
  7. Offline


    Well, didn't notice you added a stack trace. Check line 155 in your onPlayerUse listener (at me.LyesDoesPlugins.jailbreakPlugin.jailbreakMain.onPlayerUse(

    Where you said "*should*": Don't believe that your code should work the way you want it to just because you think it will.
  8. Offline


    listLocation.add(b.getLocation()); is line 155.
  9. Offline


    Given from what I said, that means there are two objects that could be null. What do you think they are?
  10. Offline


    b doesn't evolve or change in any way. It is called and set to an existing block.

    It has to be either the block or listLocation. But I don't think it can be list location, because I set it to be blank, but not null.

    Oh wait. Im guessing this is my problem:
    listLocation = jailDoorIDHash.get(id);
    While I do set listLocation to be empty, not null, before this method, I set it to jailDoorIDHash.get(id).
    Because jailDoorIDHash.get(id) doesn't get set anywhere previously, it would be null, im guessing? A simple if statement would fix this if this was the case.

    Maybe I should have worded it: "My intentions were" :p
    Last edited by a moderator: Jul 16, 2015
  11. Offline



    You can print those objects to the console to see which is null.
  12. Offline


    Using a simple if statement worked more or less, I just tweaked a few things and made it send messages to the player if everything worked out and it seems to be working. Thanks everyone!
Thread Status:
Not open for further replies.

Share This Page