[Solved] Error Help

Discussion in 'Spigot Plugin Development' started by dyenxunit, Jun 27, 2015.

Thread Status:
Not open for further replies.
  1. Hi, I was creating a GUI to open on a run of a command but now im running into all these errors when a player trys to open this GUI. It keeps showing up as null but i dont understand why.

    Code (Text):
    [10:50:26 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'test' in plugin TestPlugin
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot.jar:git-Spigot-044d928-e8c6403]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot.jar:git-Spigot-044d928-e8c6403]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:642) ~[spigot.jar:git-Spigot-044d928-e8c6403]
        at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1135) [spigot.jar:git-Spigot-044d928-e8c6403]
        at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:970) [spigot.jar:git-Spigot-044d928-e8c6403]
        at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot.jar:git-Spigot-044d928-e8c6403]
        at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot.jar:git-Spigot-044d928-e8c6403]
        at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-044d928-e8c6403]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [?:1.7.0_65]
        at java.util.concurrent.FutureTask.run(FutureTask.java:262) [?:1.7.0_65]
        at net.minecraft.server.v1_8_R3.SystemUtils.a(SystemUtils.java:19) [spigot.jar:git-Spigot-044d928-e8c6403]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:718) [spigot.jar:git-Spigot-044d928-e8c6403]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:367) [spigot.jar:git-Spigot-044d928-e8c6403]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:657) [spigot.jar:git-Spigot-044d928-e8c6403]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:560) [spigot.jar:git-Spigot-044d928-e8c6403]
        at java.lang.Thread.run(Thread.java:745) [?:1.7.0_65]
    Caused by: java.lang.NullPointerException
        at org.bukkit.craftbukkit.v1_8_R3.entity.CraftHumanEntity.openInventory(CraftHumanEntity.java:176) ~[spigot.jar:git-Spigot-044d928-e8c6403]
        at me.dyenxunit.main.GUI.FoodGUI.onCommand(FoodGUI.java:62) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot.jar:git-Spigot-044d928-e8c6403]
        ... 15 more

    Code (Text):
    public class FoodGUI implements Listener, CommandExecutor{

        public Inventory FoodMenu;
        private Main plugin;
        public FoodGUI(Main plugin) {
            this.plugin = plugin;
        public FoodGUI(Plugin p) {  
            FoodMenu = Bukkit.createInventory(null, 54,"Confirmation".replace("&","§"));
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] a) {
        if(!(sender instanceof Player)) {
    Player p = (Player) sender;
    if (cmd.getName().equalsIgnoreCase("Test")){
    return false;

    Code (Text):
    public FoodGUI fm;

    public void onEnable(){
            fm = new FoodGUI(this);
            this.getCommand("Test").setExecutor(new FoodGUI(this));
    • Funny Funny x 1
  2. Its because FoodMenu is null. You have 2 constructions in the FoodGUI class and you are obviously only using the 1st one. The 2nd one that creates the inventory is never called. Try getting rid of the 2nd constructor all together and moving the line into the 1st constructor.

    Side note: It makes it much easier for others to help you with your code if you stick with the Java conventions for class and field naming. Try to start class names with upper case and field names with lower case. E.g. use foodMenu instead of FoodMenu.
    • Informative Informative x 1
  3. Ahhhhh ok thank you so much
  4. Also, IMO, You should add a check if the FoodMenu is null, Then create it if it doesn't exist.
    • Informative Informative x 1
  5. Serializator


    Can I know why you used two constructors? And also, why do you use .replace("&", "§"); when you don't use the & character in the String you are trying to replace the character in?
  6. I was messing around with trying to get the gui from other classes that is why i have 2 constructors
Thread Status:
Not open for further replies.