2013-12-18 44 views
1

所以我有一些代碼在執行時給出了一個錯誤...的Java IndexArrayOutOfBounds問題

 if (!(sender.hasPermission("nexodus.an"))) { 
      player.sendMessage(ChatColor.BLACK + "[" + ChatColor.DARK_PURPLE + "NexodusMC" + ChatColor.BLACK + "]" + ChatColor.GREEN + " You can not do this command!"); 
      return true; 
     } else if (args.length == 0) { 
      player.sendMessage(ChatColor.BLACK + "[" + ChatColor.DARK_PURPLE + "NexodusMC" + ChatColor.BLACK + "]" + ChatColor.GREEN + " You must specify a predetermined message to broadcast!"); 
      player.sendMessage(ChatColor.BLACK + "[" + ChatColor.DARK_PURPLE + "NexodusMC" + ChatColor.BLACK + "]" + ChatColor.GREEN + " 1: Server Restarting"); 
      player.sendMessage(ChatColor.BLACK + "[" + ChatColor.DARK_PURPLE + "NexodusMC" + ChatColor.BLACK + "]" + ChatColor.GREEN + " 2: Login servers are currently down!"); 
      player.sendMessage(ChatColor.BLACK + "[" + ChatColor.DARK_PURPLE + "NexodusMC" + ChatColor.BLACK + "]" + ChatColor.GREEN + " 3: Reloading for GameModes"); 
      return true; 
     } else if (args.length > 1) { 
      if (args[0].equalsIgnoreCase("1")) { 
       Bukkit.broadcastMessage(ChatColor.BLACK + "[" + ChatColor.DARK_PURPLE + "NexodusMC" + ChatColor.BLACK + "]" + ChatColor.GREEN + " NexodusMC will be restarting in 5 seconds."); 
      } else if (args[0].equalsIgnoreCase("2")) { 
       Bukkit.broadcastMessage(ChatColor.BLACK + "[" + ChatColor.DARK_PURPLE + "NexodusMC" + ChatColor.BLACK + "]" + ChatColor.GREEN + " Login servers are currently down. Logging off my prevent you from getting back on, sorry!"); 
//Line above is line 53 || 
      } else if (args[0].equalsIgnoreCase("3")) { 
       Bukkit.broadcastMessage(ChatColor.BLACK + "[" + ChatColor.DARK_PURPLE + "NexodusMC" + ChatColor.BLACK + "]" + ChatColor.GREEN + " Server reload due to adding/removing/editing gamemodes!"); 
      } 
      return true; 
     } 

這是我的錯誤日誌。

org.bukkit.command.CommandException: Unhandled exception executing command 'an' in plugin NexodusHub vSwag 
     at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) 
     at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:192) 
     at org.bukkit.craftbukkit.v1_6_R3.CraftServer.dispatchCommand(CraftServer.java:523) 
     at net.minecraft.server.v1_6_R3.PlayerConnection.handleCommand(PlayerConnection.java:959) 
     at net.minecraft.server.v1_6_R3.PlayerConnection.chat(PlayerConnection.java:877) 
     at net.minecraft.server.v1_6_R3.PlayerConnection.a(PlayerConnection.java:834) 
     at net.minecraft.server.v1_6_R3.Packet3Chat.handle(SourceFile:49) 
     at net.minecraft.server.v1_6_R3.NetworkManager.b(NetworkManager.java:296) 
     at net.minecraft.server.v1_6_R3.PlayerConnection.e(PlayerConnection.java:116) 
     at net.minecraft.server.v1_6_R3.ServerConnection.b(SourceFile:37) 
     at net.minecraft.server.v1_6_R3.DedicatedServerConnection.b(SourceFile:30) 
     at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:592) 
     at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:227) 
     at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:488) 
     at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:421) 
     at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583) 
Caused by: java.lang.ArrayIndexOutOfBoundsException: 1 
     at me.Bling.NexodusMain.Main.onCommand(Main.java:53) # 53 is the error line. 

     at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) 
     ... 15 more 

我在做什麼錯?

回答

1

固定

改變

} else if (args.length > 1) { 

} else if (args.length > 0) {