Solved java.util.NoSuchElementException: Hashtable Enumerator

Discussion in 'Spigot Plugin Development' started by benyji, Jun 30, 2020 at 8:21 PM.

  1. Hey all,

    I'm working with a java Properties file, I simply want to check onEnable() if all the Properties are valid just incase someone doesn't know how to use Properties files and changes 'X' Instead of 'Z':
    The error is as follows:
    Code (Text):
    [15:15:47 ERROR]: Error occurred while enabling CustomOres v1.0 (Is it up to date?)
    java.util.NoSuchElementException: Hashtable Enumerator
            at java.util.Hashtable$Enumerator.nextElement(Unknown Source) ~[?:1.8.0_251]
            at java.util.Hashtable$ Source) ~[?:1.8.0_251]
            at ~[?:?]
            at com.benyji.core.Main.onEnable( ~[?:?]
            at ~[spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin( [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugin( [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugins( [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.MinecraftServer.t( [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.MinecraftServer.l( [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.MinecraftServer.a( [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.DedicatedServer.init( [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at Source) [?:1.8.0_251]
    I have a method as follows:
    Code (Java):
        public void verifyIntegrityOfSettings() {
            try {
            final Iterator<String> iterator = settings.stringPropertyNames().iterator();
            ArrayList<String> default_properties = new ArrayList<String>();
            while (iterator.hasNext()) {
                final String next =;
                final String nextResources = default_properties.toString();
                if (!(next.equals(nextResources))) {
                    main.consoleMSG(ChatColor.DARK_RED.toString() + ChatColor.BOLD + "ERROR: " + ChatColor.RED
                            + "Invalid Property in " + ChatColor.YELLOW
                            + "/plugins/CustomOres/configuration/" + ChatColor.RED + ", Property: '"
                            + ChatColor.YELLOW + + ChatColor.RED + "', Please change '" + ChatColor.YELLOW
                            + + ChatColor.RED + "' back to its original name." + ChatColor.GRAY
                            + " (use '/reload' for changes to take effect)");
        } catch (NullPointerException e) {
            System.out.println("verify integ is null");
    Line 57 in my Main class is:
    Code (Java):
    fileManager is defined as:
    Code (Java):
        private static FileManager fileManager;
    yes yes I know I used static, ignore that I can get a better way to access the FileManager class but that is besides the point right now,
    I think we've established that FileManager or fileManager is not null, as I got a null pointer exception on line 57 but once I added the Try and Catch to my method, it was null.

    Your help is greatly appreciated, if more information is needed simply ask and I will show!
  2. SteelPhoenix


    You call Iterator#next() multiple times before checking if there even are more elements. Also, why are you catching a NullPointerException?
  3. Wait wait I'm confused, I thought "while (iterator.hasNext()) {" is checking if there are more elements? If so that shouldn't be the problem since that is only being ran while there are more elements. As for the NullPointerException tbh I was kind of lazy and just wanted to quickly find if FileManager is null or if the method is, and it worked so I don't question it lol. But yeah still confused as to why its giving me that error if everything falls under "while (iterator.hasNext()) {"
  4. SteelPhoenix


    Code (Java):
    Iterable<?> iterable = Arrays.asList(1);
    Iterator<?> it = iterable.iterator(); // Has one element
    while (it.hasNext()) { // Returns true on first iteration
      Object o =; // Returns 1
      Object o2 =; // Throws NoSuchElementException - it.hasNext() returns false here
    You grab multiple elements but only check once if a next element is available
    • Agree Agree x 1
  5. Oh haha didn't realize that I did that, I'm a visual learner so I appreciate the drawn out explanation, helped me out!