Crate Plugin - NullPointerException - getConfig().set()

Discussion in 'Plugin Development' started by mccrafter1212, Jun 6, 2017.

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


    So, I've been working on this plugin for quite a while now. I've solved around 20 errors myself, although I've hit this one that's bugging me badly. I can't seem to figure out how to fix it. Here's my code where the error occurs:
    2. public void saveContents(Player plr, String name, ItemStack[] contents) {
    4. for (int i = 0; i < 25; i++) {
    6. for (int i2 = 0; i2 < getConfig().getConfigurationSection("crates").getKeys(false).size(); i2++) {
    7. if (getConfig().getString("crates." + getConfig().getConfigurationSection("crates").getKeys(false).toArray()[i2] + ".crateName").equalsIgnoreCase(name)) {
    8. System.out.println("YESS!");
    9. getConfig().set("crates." + getConfig().getConfigurationSection("crates").getKeys(false).toArray()[i2] + ".crateContents." + "CRATE_ITEM_" + Integer.toString(i) + ".content", contents[I].getType().toString());
    10. saveConfig();
    12. }
    13. }
    15. }
    17. plr.sendMessage(ChatColor.GREEN + "Successfully saved all contents!");
    19. }
    20. [/I]

    The error is:

    [14:03:05 ERROR]: Could not pass event InventoryClickEvent to CrytexCrates v1.0
    at$1.execute( ~[craftbukkit.jar:git-Bukkit-6e3cec8]
    at org.bukkit.plugin.RegisteredListener.callEvent( ~[craftbukkit.jar:git-Bukkit-6e3cec8]
    at org.bukkit.plugin.SimplePluginManager.fireEvent( [craftbukkit.jar:git-Bukkit-6e3cec8]
    at org.bukkit.plugin.SimplePluginManager.callEvent( [craftbukkit.jar:git-Bukkit-6e3cec8]
    at net.minecraft.server.v1_11_R1.PlayerConnection.a( [craftbukkit.jar:git-Bukkit-6e3cec8]
    at net.minecraft.server.v1_11_R1.PacketPlayInWindowClick.a(SourceFile:33) [craftbukkit.jar:git-Bukkit-6e3cec8]
    at net.minecraft.server.v1_11_R1.PacketPlayInWindowClick.a(SourceFile:10) [craftbukkit.jar:git-Bukkit-6e3cec8]
    at net.minecraft.server.v1_11_R1.PlayerConnectionUtils$ [craftbukkit.jar:git-Bukkit-6e3cec8]
    at java.util.concurrent.Executors$ Source) [?:1.8.0_131]
    at Source) [?:1.8.0_131]
    at net.minecraft.server.v1_11_R1.SystemUtils.a(SourceFile:46) [craftbukkit.jar:git-Bukkit-6e3cec8]
    at net.minecraft.server.v1_11_R1.MinecraftServer.D( [craftbukkit.jar:git-Bukkit-6e3cec8]
    at net.minecraft.server.v1_11_R1.DedicatedServer.D( [craftbukkit.jar:git-Bukkit-6e3cec8]
    at net.minecraft.server.v1_11_R1.MinecraftServer.C( [craftbukkit.jar:git-Bukkit-6e3cec8]
    at [craftbukkit.jar:git-Bukkit-6e3cec8]
    at Source) [?:1.8.0_131]
    Caused by: java.lang.NullPointerException
    at me.mccrafter1212.CrytexCrates.Main.saveContents( ~[?:?]
    at me.mccrafter1212.CrytexCrates.Main.onInventoryClick( ~[?:?]
    at sun.reflect.GeneratedMethodAccessor23.invoke(Unknown Source) ~[?:?]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_131]
    at$1.execute( ~[craftbukkit.jar:git-Bukkit-6e3cec8]
    ... 15 more

    I realize that it talks about an event, although the event is linking to that function and the error is occurring on the line that says:
    getConfig().set(blah blah blah);

    Please, help!

    EDIT: My config.yml @Zombie_Striker
    crateName: Example
    crateId: 0
    content: DIAMOND

    So, what I'm trying to do is create a new thing inside of crateContents (although, sometimes crateContents doesn't exist because you can create crates from commands which only sets up the crateName, and crateId.
    Last edited: Jun 6, 2017
  2. Offline


    1. Is the config null.
    2. Is the configuration section null.
    3. Isthe object at the array i2 null?
    4. Is contents at i null?

    BTW: I is already an int. You do not need to use the Integer.value method on it.
Thread Status:
Not open for further replies.

Share This Page