HELP: Unhandled exception executing command

Discussion in 'Plugin Development' started by spyrootjenl, Aug 28, 2016.

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

    spyrootjenl

    Code:
    Spyrootje issued server command: /acraft
    [18:18:29 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'acraft' in plugin AutoCrafter v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot.jar:git-Spigot-90f61bc-83a9dbd]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) ~[spigot.jar:git-Spigot-90f61bc-83a9dbd]
            at org.bukkit.craftbukkit.v1_10_R1.CraftServer.dispatchCommand(CraftServer.java:646) ~[spigot.jar:git-Spigot-90f61bc-83a9dbd]
            at net.minecraft.server.v1_10_R1.PlayerConnection.handleCommand(PlayerConnection.java:1351) [spigot.jar:git-Spigot-90f61bc-83a9dbd]
            at net.minecraft.server.v1_10_R1.PlayerConnection.a(PlayerConnection.java:1186) [spigot.jar:git-Spigot-90f61bc-83a9dbd]
            at net.minecraft.server.v1_10_R1.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot.jar:git-Spigot-90f61bc-83a9dbd]
            at net.minecraft.server.v1_10_R1.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot.jar:git-Spigot-90f61bc-83a9dbd]
            at net.minecraft.server.v1_10_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-90f61bc-83a9dbd]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_102]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_102]
            at net.minecraft.server.v1_10_R1.SystemUtils.a(SourceFile:45) [spigot.jar:git-Spigot-90f61bc-83a9dbd]
            at net.minecraft.server.v1_10_R1.MinecraftServer.D(MinecraftServer.java:732) [spigot.jar:git-Spigot-90f61bc-83a9dbd]
            at net.minecraft.server.v1_10_R1.DedicatedServer.D(DedicatedServer.java:400) [spigot.jar:git-Spigot-90f61bc-83a9dbd]
            at net.minecraft.server.v1_10_R1.MinecraftServer.C(MinecraftServer.java:668) [spigot.jar:git-Spigot-90f61bc-83a9dbd]
            at net.minecraft.server.v1_10_R1.MinecraftServer.run(MinecraftServer.java:567) [spigot.jar:git-Spigot-90f61bc-83a9dbd]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_102]
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
            at spyrootje.craftstick.onCommand(craftstick.java:22) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot.jar:git-Spigot-90f61bc-83a9dbd]
            ... 15 more

    im getting the error as shows above and i have no idea what the problem is, i only get it when executing /acraft but not when i do /acraft claim or flag
     
    Last edited by a moderator: Aug 28, 2016
  2. Offline

    Oxyorum

    @spyrootjenl

    That is the problem. Make sure that you are not trying to use indexes of arrays that are greater than the array's length.

    In this case, the array causing the exception has a length of 0.
     
  3. Offline

    spyrootjenl

    Player player = (Player) sender;
    if(!(sender instanceof Player)) {
    sender.sendMessage("You need to be a player to execute that command");
    return true;

    }
    if (args[0] == null) {
    player.sendMessage("Usage = /acraft <item>");
    }
    else if (args[0].equalsIgnoreCase("claim")) {
    player.sendMessage("Usage = /acraft <item>claimnn");
    }
    else if (args[0].equalsIgnoreCase("flag")) {
    player.sendMessage("Usage = /acraft <item>flagmm");
    }
    else {
    player.sendMessage(".... is not a correct item name!");
    }
    This is the code, i cant find a error, can you help?
     
  4. @spyrootjenl
    Don't check if "args[0]" equals null. Check args.length instead.
     
    Oxyorum likes this.
Thread Status:
Not open for further replies.

Share This Page