Solved java.lang.ArrayIndexOutOfBoundsException

Discussion in 'Plugin Development' started by DomThePotato, Nov 22, 2014.

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

    DomThePotato

    Hello, I'm sure you have seen forums being posted about this all the time. But I have gone round the so many websites and not found a solution. I have been trying to fix it for the last 2 hours and have had no luck. So I gave up and I'm now doing this, making a forum post. So I am trying to make like a big plugin for a hub and I am doing a /kick command. So I can do /kick (player) and it kicks but I want it so if you do /kick is shows usage. E.g. Usage: /kick (Player) (Reason). Then I get this error

    22.11 15:55:19[Server]INFO ... 13 more 22.11 15:55:19[Server]INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit-dev.jar:git-Bukkit-1.7.9-R0.1-9-gaceeb44-b3091jnks] 22.11 15:55:19[Server]INFO at me.CryticNetwork.MainCmds.onCommand(MainCmds.java:72) ~[?:?] 22.11 15:55:19 [Server] INFO Caused by: java.lang.ArrayIndexOutOfBoundsException: 122.11 15:55:19[Server]INFO at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [craftbukkit-dev.jar:git-Bukkit-1.7.9-R0.1-9-gaceeb44-b3091jnks] 22.11 15:55:19[Server]INFO at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:469) [craftbukkit-dev.jar:git-Bukkit-1.7.9-R0.1-9-gaceeb44-b3091jnks] 22.11 15:55:19[Server]INFO at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:558) [craftbukkit-dev.jar:git-Bukkit-1.7.9-R0.1-9-gaceeb44-b3091jnks] 22.11 15:55:19[Server]INFO at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:260) [craftbukkit-dev.jar:git-Bukkit-1.7.9-R0.1-9-gaceeb44-b3091jnks] 22.11 15:55:19[Server]INFO at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:667) [craftbukkit-dev.jar:git-Bukkit-1.7.9-R0.1-9-gaceeb44-b3091jnks] 22.11 15:55:19[Server]INFO at net.minecraft.server.v1_7_R3.ServerConnection.c(SourceFile:134) [craftbukkit-dev.jar:git-Bukkit-1.7.9-R0.1-9-gaceeb44-b3091jnks] 22.11 15:55:19[Server]INFO at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:157) [craftbukkit-dev.jar:git-Bukkit-1.7.9-R0.1-9-gaceeb44-b3091jnks] 22.11 15:55:19[Server]INFO at net.minecraft.server.v1_7_R3.PacketPlayInChat.handle(PacketPlayInChat.java:47) [craftbukkit-dev.jar:git-Bukkit-1.7.9-R0.1-9-gaceeb44-b3091jnks] 22.11 15:55:19[Server]INFO at net.minecraft.server.v1_7_R3.PacketPlayInChat.a(PacketPlayInChat.java:28) [craftbukkit-dev.jar:git-Bukkit-1.7.9-R0.1-9-gaceeb44-b3091jnks] 22.11 15:55:19[Server]INFO at net.minecraft.server.v1_7_R3.PlayerConnection.a(PlayerConnection.java:817) [craftbukkit-dev.jar:git-Bukkit-1.7.9-R0.1-9-gaceeb44-b3091jnks] 22.11 15:55:19[Server]INFO at net.minecraft.server.v1_7_R3.PlayerConnection.handleCommand(PlayerConnection.java:956) [craftbukkit-dev.jar:git-Bukkit-1.7.9-R0.1-9-gaceeb44-b3091jnks] 22.11 15:55:19[Server]INFO at org.bukkit.craftbukkit.v1_7_R3.CraftServer.dispatchCommand(CraftServer.java:701) ~[craftbukkit-dev.jar:git-Bukkit-1.7.9-R0.1-9-gaceeb44-b3091jnks] 22.11 15:55:19[Server]INFO at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:180) ~[craftbukkit-dev.jar:git-Bukkit-1.7.9-R0.1-9-gaceeb44-b3091jnks] 22.11 15:55:19[Server]INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit-dev.jar:git-Bukkit-1.7.9-R0.1-9-gaceeb44-b3091jnks] 22.11 15:55:19[Server]INFO org.bukkit.command.CommandException: Unhandled exception executing command 'kick' in plugin CrypticHub v1.0 22.11 15:55:19 [Server] ERROR null#


    Then I go back and check the code for line 72:
    Player t = p.getServer().getPlayer(args[1]);
    Code:java
    1. Player t = p.getServer().getPlayer(args[1]);


    Here is the whole command syntax:

    Code:java
    1. if(cmd.getName().equalsIgnoreCase("kick")) {
    2.  
    3. if(sender.hasPermission(new Permissions().kick)){
    4.  
    5. Player t = p.getServer().getPlayer(args[1]);
    6.  
    7. if(t == null){
    8.  
    9. sender.sendMessage(ChatColor.DARK_GREEN+"[Cryptic Network] "+ChatColor.BLUE+" Usage: "+ChatColor.GOLD+"/kick (User) (Reason)");
    10.  
    11. }}
    12.  
    13. else{
    14.  
    15. sender.sendMessage(ChatColor.DARK_GREEN+"[Cryptic Network]"+ChatColor.DARK_RED+" Not enough permissions... If there is a problem ask a member of staff.");
    16.  
    17. }
    18.  
    19. if(sender.hasPermission(new Permissions().kick)){
    20.  
    21. Player t = p.getServer().getPlayer(args[0]);
    22.  
    23. if(t == null){
    24.  
    25. sender.sendMessage(ChatColor.DARK_GREEN+"[Cryptic Network]"+ChatColor.DARK_RED+" Uh oh... Couldn't find the specified player "+ChatColor.GOLD+args[0]+ChatColor.DARK_RED+"!");
    26.  
    27. return true;}
    28.  
    29.  
    30.  
    31. t.kickPlayer(ChatColor.DARK_RED+"You have been kicked from the server.");
    32.  
    33. sender.sendMessage(ChatColor.DARK_GREEN+"[Cryptic Network] "+ChatColor.BLUE+" Successfully kicked "+ChatColor.GOLD+args[0]+ChatColor.BLUE+" from the server.");
    34.  
    35. }}
    36.  
    37. return false;}}
    38.  
    39.  


    Thanks for reading. :D
     
  2. Offline

    timtower Moderator Moderator

  3. Offline

    DomThePotato

  4. Offline

    timtower Moderator Moderator

    DomThePotato You aren't checking the size of the array before you access it.
     
  5. Offline

    mine-care

  6. Offline

    DomThePotato

    Ok, sorry I had some silly mistakes in there I didn't notice. Thanks for helping though :D.
     
Thread Status:
Not open for further replies.

Share This Page