这篇文章主要介绍了java 中遍历取值异常(hashtable enumerator)解决办法的相关资料,用迭代器取值时抛出的异常:java.util.nosuchelementexception: hashtable enumerator ,需要的朋友可以参考下
java中遍历取值异常报错的解决办法
用迭代器取值时抛出的异常:java.util.nosuchelementexception: hashtable enumerator
示例代码
//使用迭代器遍历
iterator<string> it = tableproper.stringpropertynames().iterator();
sqlmap = new hashmap<string,string>();
while(it.hasnext()){
sqlmap.put(it.next(), tableproper.getproperty(it.next()));
}
这是一个枚举异常,是因为在还没来得及执行it.next()时就开始引用它。我们可以用如下方式解决此问题:
//使用迭代器遍历
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));
}
以上就是java中遍历取值异常报错的解决办法的详细内容。
