This article mainly introduces the relevant information about the solution to the traversal value exception (Hashtable Enumerator) in Java. The exception thrown when using the iterator to obtain the value: java.util.NoSuchElementException: Hashtable Enumerator. Friends in need can refer to it. Next
Solution to the exception error when traversing value in Java
Exception thrown when using iterator to obtain value: java.util.NoSuchElementException: Hashtable Enumerator
Sample code
//使用迭代器遍历 Iterator<String> it = tableProper.stringPropertyNames().iterator(); sqlMap = new HashMap<String,String>(); while(it.hasNext()){ sqlMap.put(it.next(), tableProper.getProperty(it.next())); }
This is an enumeration exception because it.next() has not yet been executed. Start quoting it. We can solve this problem as follows:
//使用迭代器遍历 Iterator<String> it = tableProper.stringPropertyNames().iterator(); sqlMap = new HashMap<String,String>(); String key; while(it.hasNext()){ key = it.next(); sqlMap.put(key, tableProper.getProperty(key)); }
The above is the detailed content of Solution to error reporting when traversing values in Java. For more information, please follow other related articles on the PHP Chinese website!