这篇文章主要介绍了java 中遍历取值异常(hashtable enumerator)解决办法的相关资料,用迭代器取值时抛出的异常:java.util.nosuchelementexception: hashtable enumerator ,需要的朋友可以参考下
Java中遍历取值异常报错的解决办法
用迭代器取值时抛出的异常:java.util.NoSuchElementException: Hashtable Enumerator
示例代码
//使用迭代器遍历
Iterator it = tableProper.stringPropertyNames().iterator();
sqlMap = new HashMap();
while(it.hasNext()){
sqlMap.put(it.next(), tableProper.getProperty(it.next()));
} 这是一个枚举异常,是因为在还没来得及执行it.next()时就开始引用它。我们可以用如下方式解决此问题:
立即学习“Java免费学习笔记(深入)”;
//使用迭代器遍历
Iterator it = tableProper.stringPropertyNames().iterator();
sqlMap = new HashMap();
String key;
while(it.hasNext()){
key = it.next();
sqlMap.put(key, tableProper.getProperty(key));
}











