Solved Internal Error help

Discussion in 'Plugin Development' started by DutchChris, Aug 13, 2020.

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

    DutchChris

    So I was trying to get back into coding, but ran into an issue. Upon running the givecash command in my localhost server with an argument behind it, it gives me an internal error. Just /givecash works fine and returns the message, but as soon as I add an argument it turns into an error. Would like to know why adding an argument such as 1 or 2 causes an error. Thanks!

    Code:
    @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (cmd.getName().equalsIgnoreCase("balance")) {
                sender.sendMessage("Your balance is " + balance);
                return true;
            } else if(cmd.getName().equalsIgnoreCase("store")) {
                balance += cash;
                sender.sendMessage("You stored " + cash + "! Your new balance is " + balance);
                cash = 0;
            } else if(cmd.getName().equalsIgnoreCase("givecash")) {
                if(args.length < 1) {
                    sender.sendMessage("Please enter a valid amount of cash");
                }
                else if(isInt(args[1])) {
                         int money = Integer.parseInt(args[1]);
                         sender.sendMessage("You received " + money + " money");
                         balance += money;
                }
            }
               
           
           
           
           
            return false;
        }
       
       
    }
    Console:

    [18:15:07 INFO]: DutchChris_ issued server command: /givecash 1
    [18:15:07 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'givecash' in plugin fuckinghell v1.12.2
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit-1.12.2.jar:git-Bukkit-e60fc34]
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) ~[craftbukkit-1.12.2.jar:git-Bukkit-e60fc34]
    at org.bukkit.craftbukkit.v1_12_R1.CraftServer.dispatchCommand(CraftServer.java:628) ~[craftbukkit-1.12.2.jar:git-Bukkit-e60fc34]
    at net.minecraft.server.v1_12_R1.PlayerConnection.handleCommand(PlayerConnection.java:1340) [craftbukkit-1.12.2.jar:git-Bukkit-e60fc34]
    at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:1200) [craftbukkit-1.12.2.jar:git-Bukkit-e60fc34]
    at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(SourceFile:37) [craftbukkit-1.12.2.jar:git-Bukkit-e60fc34]
    at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(SourceFile:9) [craftbukkit-1.12.2.jar:git-Bukkit-e60fc34]
    at net.minecraft.server.v1_12_R1.PlayerConnectionUtils$1.run(SourceFile:13) [craftbukkit-1.12.2.jar:git-Bukkit-e60fc34]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_241]
    at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_241]
    at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46) [craftbukkit-1.12.2.jar:git-Bukkit-e60fc34]
    at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:696) [craftbukkit-1.12.2.jar:git-Bukkit-e60fc34]
    at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:371) [craftbukkit-1.12.2.jar:git-Bukkit-e60fc34]
    at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:651) [craftbukkit-1.12.2.jar:git-Bukkit-e60fc34]
    at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:555) [craftbukkit-1.12.2.jar:git-Bukkit-e60fc34]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_241]
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
    at fuckinghell.Main.onCommand(Main.java:44) ~[?:?]
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit-1.12.2.jar:git-Bukkit-e60fc34]
    ... 15 more
     
  2. Offline

    timtower Moderator Moderator

    @DutchChris Java starts counting at 0, not at 1 like you are doing.
     
  3. Offline

    DutchChris

    Ah that solved it. Thanks for the help!
     
Thread Status:
Not open for further replies.

Share This Page