Solved java.util.NoSuchElementException help.

Discussion in 'Plugin Help/Development/Requests' started by x_Jake_s, Apr 12, 2015.

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

    x_Jake_s

    After creating my OITQ plugin which is viewable at
    Show Spoiler
    <Edit by Moderator: Redacted not allowed paid resource url>

    or at
    Show Spoiler


    i have noticed that when my /oitq list is empty this error is returned, my question is how do i point it away from sending the error log and instead a "No arenas" message?


    Show Spoiler
    [21:17:24] [Server thread/INFO]: Frostfire_MC issued server command: /oitq list
    [21:17:24] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'oitq' in plugin SOITC v1.2
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot.jar:git-Spigot-c136710-350cb99]
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot.jar:git-Spigot-c136710-350cb99]
    at org.bukkit.craftbukkit.v1_8_R2.CraftServer.dispatchCommand(CraftServer.java:646) ~[spigot.jar:git-Spigot-c136710-350cb99]
    at net.minecraft.server.v1_8_R2.PlayerConnection.handleCommand(PlayerConnection.java:1133) [spigot.jar:git-Spigot-c136710-350cb99]
    at net.minecraft.server.v1_8_R2.PlayerConnection.a(PlayerConnection.java:968) [spigot.jar:git-Spigot-c136710-350cb99]
    at net.minecraft.server.v1_8_R2.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot.jar:git-Spigot-c136710-350cb99]
    at net.minecraft.server.v1_8_R2.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot.jar:git-Spigot-c136710-350cb99]
    at net.minecraft.server.v1_8_R2.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-c136710-350cb99]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.7.0_75]
    at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.7.0_75]
    at net.minecraft.server.v1_8_R2.SystemUtils.a(SourceFile:60) [spigot.jar:git-Spigot-c136710-350cb99]
    at net.minecraft.server.v1_8_R2.MinecraftServer.A(MinecraftServer.java:710) [spigot.jar:git-Spigot-c136710-350cb99]
    at net.minecraft.server.v1_8_R2.DedicatedServer.A(DedicatedServer.java:368) [spigot.jar:git-Spigot-c136710-350cb99]
    at net.minecraft.server.v1_8_R2.MinecraftServer.z(MinecraftServer.java:651) [spigot.jar:git-Spigot-c136710-350cb99]
    at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java:554) [spigot.jar:git-Spigot-c136710-350cb99]
    at java.lang.Thread.run(Unknown Source) [?:1.7.0_75]
    Caused by: java.util.NoSuchElementException
    at java.util.ArrayList$Itr.next(Unknown Source) ~[?:1.7.0_75]
    at me.kale.soitc.cmdExecutors.OITQCommandExecutor.onCommand(OITQCommandExecutor.java:105) ~[?:?]
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot.jar:git-Spigot-c136710-350cb99]
    ... 15 more



    Show Spoiler
    Caused by: java.util.NoSuchElementException
    at java.util.ArrayList$Itr.next(Unknown Source) ~[?:1.7.0_75]
    at me.kale.soitc.cmdExecutors.OITQCommandExecutor.onCommand(OITQCommandExecutor.java:105) ~[?:?]




    Show Spoiler
    Code:
    java said: 
              ArenaRunner arena;
              if (args[0].equalsIgnoreCase("list")) {
                  if (sender.hasPermission("oitq.list")) {
                      String arenas = "List of Arenas " + ChatColor.DARK_AQUA;
                    Iterator<ArenaRunner> localIterator = ArenaStorage.getArenas().iterator();
                    localIterator.hasNext();
                      {
                        arena = (ArenaRunner) localIterator.next(); //Error points to here//
                        arenas = arenas + arena.getName() + ", ";
                          }
                      player.sendMessage(prefix + ChatColor.GREEN +  arenas);
                    }
              }
                  }
     
    Last edited by a moderator: Dec 5, 2016
  2. Offline

    FisheyLP

    do:
    while (localIterator.hasNext()) {
    and not
    localIterator.hasNext();
    {
     
  3. Offline

    mine-care

    Code:
     localIterator.hasNext();
     [*]                  {
                         arena = (ArenaRunner) localIterator.next(); //Error points to here//
                         arenas = arenas + arena.getName() + ", ";
                           }
    Err. is this thing even working? Shouldnt there be a loop? (unless it is java 8 where i have litle knowledge on)
     
  4. Offline

    FisheyLP

    while(localIterator.hasNext()) {
    //do stuff
    }
     
  5. Offline

    x_Jake_s

    1) im coding in Java 7, and my method DID work, the only problem was when it was empty, or there were no arenas, an error was sent to the console, when i imput the method
    while(localIterator.hasNext()) {
    }
    Code:
    Code:
              ArenaRunner arena;
              if (args[0].equalsIgnoreCase("list")) {
                  if (sender.hasPermission("oitq.list")) {
                      String arenas = "List of Arenas " + ChatColor.DARK_AQUA;
                    Iterator<ArenaRunner> localIterator = ArenaStorage.getArenas().iterator();
                    localIterator.hasNext();
                      {
                        arena = (ArenaRunner) localIterator.next();
                        arenas = arenas + arena.getName() + ", ";
                          }
                      player.sendMessage(prefix + ChatColor.GREEN +  arenas);
                    }
              }
                  }
    i get this error, and my server crashes :

    http://pastebin.com/tVMVwyuW

    So i screwed around a bit more with it and found out that this code:
    Code:
                ArenaRunner arena;
                if (args[0].equalsIgnoreCase("list"))
                {
                  String arenas = prefix + "List of Arenas - " + ChatColor.DARK_AQUA;
                  for (Iterator localIterator = ArenaStorage.getArenas().iterator(); localIterator.hasNext();)
                  {
                    arena = (ArenaRunner)localIterator.next();
                    arenas = arenas + arena.getName() + ", ";
                  }
                  player.sendMessage(arenas);
                }
                  }
    returns
    just "prefix + List of Arenas - " and nothing else so that will do nicely.

    //Solved//

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
Thread Status:
Not open for further replies.

Share This Page