Solved NPE?

Discussion in 'Spigot Plugin Development' started by gluebaby, Jun 5, 2016.

  1. Hey guys, I come with an error xD. I am a little embarrassed to post, because in all honesty it is probably a super simple error and I will feel like a nub. So here is the console log on startup:

    Code (Text):
    [10:14:04 INFO]: [CombatBeta] Enabling CombatBeta v1.0
    [10:14:04 ERROR]: Error occurred while enabling CombatBeta v1.0 (Is it up to date?)
    java.lang.NullPointerException
        at me.undeadguppy.combatbeta.Main.onEnable(Main.java:21) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:414) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:378) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:333) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:263) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:525) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at java.lang.Thread.run(Thread.java:745) [?:1.8.0_65]
     
    Its kind of odd, because recently all my plugins I have compiled have given me a similar error... I have a feeling its to do with a bad spigot.jar but I don't know. Any ideas?

    A few things I think it may be:
    - Having a corrupted spigot.jar
    - Having multiple commands in a CommandExecutor class (Not multiple booleans, just cmd.getName().
     
  2. Show us Main.java at line 21
     
  3. My entire main class (line 21 is getCommand("kit"):

    Code (Text):
    package me.undeadguppy.combatbeta;

    import org.bukkit.Bukkit;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;

    import me.undeadguppy.combatbeta.Commands.Kits;
    import me.undeadguppy.combatbeta.Commands.Shop;
    import me.undeadguppy.combatbeta.Listeners.DeathMessages;
    import me.undeadguppy.combatbeta.Listeners.JoinLeave;
    import me.undeadguppy.combatbeta.Listeners.MobDeath;
    import me.undeadguppy.combatbeta.Listeners.NoCash;

    public class Main extends JavaPlugin {

        Kits kit = new Kits();
        Shop shop = new Shop();
        PluginManager pm = Bukkit.getServer().getPluginManager();

        public void onEnable() {
            getCommand("kit").setExecutor(kit);
            getCommand("kits").setExecutor(kit);
            getCommand("shop").setExecutor(shop);
            getCommand("buy").setExecutor(shop);
            getCommand("sell").setExecutor(shop);
            getCommand("transfer").setExecutor(shop);
            getCommand("balance").setExecutor(shop);
            pm.registerEvents(new MobDeath(), this);
            pm.registerEvents(new NoCash(), this);
            pm.registerEvents(new JoinLeave(), this);
            pm.registerEvents(new DeathMessages(), this);
            if (Bukkit.getServer().getPluginManager().getPlugin("MineConomy") == null) {
                getLogger().severe("Disabled due to no dependancy found");
                pm.disablePlugin(this);
                return;
            }

        }

        public void onDisable() {

        }

    }
     
     
  4. Did you register the command "kit" in your plugin.yml? Also, don't register new commands with the same command executor, instead, use the aliases option in your plugin.yml.
     
  5. Just did that, and that seems to have fixed it. Thanks!