Unhandled Exception

Discussion in 'Plugin Development' started by top2001, Feb 18, 2015.

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

    top2001

    Hello Bukit.

    I was wondering which part of my code below could be errorring out and giving me an internal error. When I do the command, it does what I want it to do beside from sending the the success message and sending me an internal error message instead.

    Here's the code:

    Code:
                }else if(cmd.getName().equalsIgnoreCase("electros")){
                    if(player.hasPermission("electronetworks.electros")) {
                        if(args.length == 0) {
                            player.sendMessage(prefix + ChatColor.RED + "Invalid arguments.");
                        }else if(args[0].equalsIgnoreCase("add")) {
                            int amount = Integer.parseInt(args[1]);
                            Player target = Bukkit.getServer().getPlayer(args[2]);
                            this.plugin.getConfig().set("Electros." + target.getUniqueId() + ".Balance", (this.plugin.getConfig().getInt("Electros." + target.getUniqueId() + ".Balance") + amount));
                            this.plugin.saveConfig();
                            player.sendMessage(prefix + ChatColor.YELLOW + "Successfully added " + ChatColor.GOLD + args[1] + ChatColor.YELLOW + "Electros to the user: " + ChatColor.GOLD + args[3]);
    And here's the console error:

    Code:
    18.02 21:51:42 [Server] INFO ... 14 more
    18.02 21:51:42 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot-1.8.jar:git-Spigot-b1e6da1-1092acb]
    18.02 21:51:42 [Server] INFO at me.top2001.ElectroNetworksHub.Commands.onCommand(Commands.java:172) ~[?:?]
    18.02 21:51:42 [Server] INFO Caused by: java.lang.ArrayIndexOutOfBoundsException: 3
    18.02 21:51:42 [Server] INFO at java.lang.Thread.run(Thread.java:745) [?:1.8.0_25]
    18.02 21:51:42 [Server] INFO at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:526) [spigot-1.8.jar:git-Spigot-b1e6da1-1092acb]
    18.02 21:51:42 [Server] INFO at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:623) [spigot-1.8.jar:git-Spigot-b1e6da1-1092acb]
    18.02 21:51:42 [Server] INFO at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:316) [spigot-1.8.jar:git-Spigot-b1e6da1-1092acb]
    18.02 21:51:42 [Server] INFO at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:683) [spigot-1.8.jar:git-Spigot-b1e6da1-1092acb]
    18.02 21:51:42 [Server] INFO at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_25]
    18.02 21:51:42 [Server] INFO at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_25]
    18.02 21:51:42 [Server] INFO at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [spigot-1.8.jar:git-Spigot-b1e6da1-1092acb]
    18.02 21:51:42 [Server] INFO at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java:53) [spigot-1.8.jar:git-Spigot-b1e6da1-1092acb]
    18.02 21:51:42 [Server] INFO at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java:26) [spigot-1.8.jar:git-Spigot-b1e6da1-1092acb]
    18.02 21:51:42 [Server] INFO at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java:950) [spigot-1.8.jar:git-Spigot-b1e6da1-1092acb]
    18.02 21:51:42 [Server] INFO at net.minecraft.server.v1_8_R1.PlayerConnection.handleCommand(PlayerConnection.java:1115) [spigot-1.8.jar:git-Spigot-b1e6da1-1092acb]
    18.02 21:51:42 [Server] INFO at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServer.java:645) ~[spigot-1.8.jar:git-Spigot-b1e6da1-1092acb]
    18.02 21:51:42 [Server] INFO at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot-1.8.jar:git-Spigot-b1e6da1-1092acb]
    18.02 21:51:42 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot-1.8.jar:git-Spigot-b1e6da1-1092acb]
    18.02 21:51:42 [Server] INFO org.bukkit.command.CommandException: Unhandled exception executing command 'electros' in plugin ElectroNetworksHub v1.0
    
     
  2. Offline

    _Filip

  3. Offline

    Zombie_Striker

    Line 5 of the errors says
    Since you cut off your code at the end, I have no idea how to help you. Please post everything that command does and what you type for the command, that way we can figure out whats the problem since it doesn't say which line is causing the error.

    Also, you should try instead of getting the player as an Integer, you should get the player name instead.
     
  4. Offline

    top2001

    That is the whole command, all the brackets and that are all in the correct place and that. The reason I am not showing above the command I gave is that I don't want the plugin for my server to be public. In my opinion, you don't need to see the whole piece of code. Also, the integer isn't a player.
     
  5. Offline

    jimbo8

    There is an argument too much.

    This line of code says that you are getting args[3], when you should get args[2]:

    Code:
    player.sendMessage(prefix + ChatColor.YELLOW+"Successfully added "+ ChatColor.GOLD+ args[1]+ ChatColor.YELLOW+"Electros to the user: "+ ChatColor.GOLD+ args[3]);
    
     
  6. Offline

    top2001

    Ah. Thanks for your help :D
     
    jimbo8 likes this.
Thread Status:
Not open for further replies.

Share This Page