NullPointer?

Discussion in 'Spigot Plugin Development' started by OldTimes, May 1, 2015.

Thread Status:
Not open for further replies.
  1. Error:
    Code (Text):
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot.jar:git-Spigot-4faf77a-17a3db7]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot.jar:git-Spigot-4faf77a-17a3db7]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServer.java:646) ~[spigot.jar:git-Spigot-4faf77a-17a3db7]
        at net.minecraft.server.v1_8_R1.PlayerConnection.handleCommand(PlayerConnection.java:1115) [spigot.jar:git-Spigot-4faf77a-17a3db7]
        at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java:950) [spigot.jar:git-Spigot-4faf77a-17a3db7]
        at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java:26) [spigot.jar:git-Spigot-4faf77a-17a3db7]
        at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java:53) [spigot.jar:git-Spigot-4faf77a-17a3db7]
        at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [spigot.jar:git-Spigot-4faf77a-17a3db7]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.7.0_75]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.7.0_75]
        at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:696) [spigot.jar:git-Spigot-4faf77a-17a3db7]
        at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:316) [spigot.jar:git-Spigot-4faf77a-17a3db7]
        at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:634) [spigot.jar:git-Spigot-4faf77a-17a3db7]
        at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:537) [spigot.jar:git-Spigot-4faf77a-17a3db7]
        at java.lang.Thread.run(Unknown Source) [?:1.7.0_75]
    Caused by: java.lang.NullPointerException
        at GUI.AchievementGUI.addLores(AchievementGUI.java:57) ~[?:?]
        at GUI.AchievementGUI.setLores(AchievementGUI.java:49) ~[?:?]
        at GUI.AchievementGUI.openAchievementGUI(AchievementGUI.java:34) ~[?:?]
        at Commands.AchievementCMD.onCommand(AchievementCMD.java:19) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot.jar:git-Spigot-4faf77a-17a3db7]
        ... 14 more
    Thanks!
     
    #1 OldTimes, May 1, 2015
    Last edited: May 1, 2015
  2. gigosaurus

    Supporter

    The NPE is because you never initialize this:
    static ArrayList<String> tenKillsLore;

    You could probaby just change it to this and it'll work fine:
    static ArrayList<String> tenKillsLore = new ArrayList<String>();
     
    • Agree Agree x 1
  3. I think I found another NPE.

    "Stats." + p.getUniqueId().toString() + ".Achievements." + s)) {

    Code (Text):
            static boolean isUnlocked(Player p, boolean s) {
                    if (dm.getData().getBoolean(
                                    "Stats." + p.getUniqueId().toString() + ".Achievements." + s)) {
                            return true;
                    } else
                            return false;
            }
     
  4. @gigosaurus Thanks, It's fixed!

    However I still have a small problem:
    Code (Text):
        static boolean isUnlocked(Player p, boolean s) {
            if (dm.getData().getBoolean(
                    "Stats." + p.getUniqueId().toString() + ".Achievements." + s)) {
                return true;
            } else
                return false;
        }
    This isn't working, and is always passing as false, even though the YML is set to true?
     
  5. After Achievements you check a boolean --> Stats.0000-0000(etc).Achievements.true: true

    Might want to check the achievement.
     
  6. gigosaurus

    Supporter

    You already checked if it was unlocked back in the setLores method.
    Change "if (isUnlocked(p, s)) {" in addLores to "if (s) {"
     
  7. Fixed it, it was a mistake with Strings values.

    Thanks!
     
  8. dtm

    dtm Retired Moderator
    Retired Supporter

    Thread locked per request.
     
    • Like Like x 1
    • Agree Agree x 1
Thread Status:
Not open for further replies.