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

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

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

    mccrafter1212

    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:
    Code:java
    1.  
    2. public void saveContents(Player plr, String name, ItemStack[] contents) {
    3.  
    4. for (int i = 0; i < 25; i++) {
    5.  
    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();
    11.  
    12. }
    13. }
    14.  
    15. }
    16.  
    17. plr.sendMessage(ChatColor.GREEN + "Successfully saved all contents!");
    18.  
    19. }
    20. [/I]


    The error is:

    [14:03:05 ERROR]: Could not pass event InventoryClickEvent to CrytexCrates v1.0
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:298) ~[craftbukkit.jar:git-Bukkit-6e3cec8]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-6e3cec8]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit.jar:git-Bukkit-6e3cec8]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-6e3cec8]
    at net.minecraft.server.v1_11_R1.PlayerConnection.a(PlayerConnection.java:1780) [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$1.run(SourceFile:13) [craftbukkit.jar:git-Bukkit-6e3cec8]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_131]
    at java.util.concurrent.FutureTask.run(Unknown 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(MinecraftServer.java:695) [craftbukkit.jar:git-Bukkit-6e3cec8]
    at net.minecraft.server.v1_11_R1.DedicatedServer.D(DedicatedServer.java:360) [craftbukkit.jar:git-Bukkit-6e3cec8]
    at net.minecraft.server.v1_11_R1.MinecraftServer.C(MinecraftServer.java:650) [craftbukkit.jar:git-Bukkit-6e3cec8]
    at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:554) [craftbukkit.jar:git-Bukkit-6e3cec8]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_131]
    Caused by: java.lang.NullPointerException
    at me.mccrafter1212.CrytexCrates.Main.saveContents(Main.java:94) ~[?:?]
    at me.mccrafter1212.CrytexCrates.Main.onInventoryClick(Main.java:354) ~[?:?]
    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 org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:296) ~[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
    crates:
    ExampleAlias:
    crateName: Example
    crateId: 0
    crateContents:
    Diamond_Content:
    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

    Zombie_Striker

    @mccrafter1212
    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