关于java学习之中遇到的一些问题之:java.util.NoSuchElementException.
2015-05-05 20:39
751 查看
今天在做编译原理实验的时候,我用到java.util.HashMap
Set ba = basic.keySet(); Set nu = num.keySet(); Set sy = symbalchar.keySet(); Set ot = other.keySet(); Iterator ba1 =ba.iterator(); Iterator nu1 =nu.iterator(); Iterator sy1 =sy.iterator(); Iterator oth1 =ot.iterator(); while(ba1.hasNext()) { String bnex =(String)ba1.next(); String bre =(String)basic.get(bnex); result.append("("+bnex+","+bre+")"+"\r\n"); } while(nu1.hasNext()) { String nnex =(String)nu1.next(); String nre =(String)num.get(nnex); result.append("常数:"+"("+nnex+","+nre+")"+"\r\n"); } while(sy1.hasNext()) { String snex =(String)sy1.next(); int sre =(Integer)symbalchar.get(snex); result.append("标识符:"+"("+snex+","+sre+")"+"\r\n"); } while(oth1.hasNext()) { String onex =(String)oth1.next(); String ore =(String)other.get(onex); result.append("("+onex+","+ore+")"+"\r\n"); }
时,遇到了java.util.NoSuchElementException.
经过查找发现是由于Iterator 发生越界,导致异常,
当时的错误代码是
<pre name="code" class="java">result.append("("+ba1.next()+","+basichar.get(ba1.next())+")"+"\r\n");//basichar是HashMap的一个对象
原来出现两个ba1.next()从而导致越界异常,后改为最上方的代码,问题成功解决
相关文章推荐
- 关于java.util.NoSuchElementException错误
- 关于java.util.NoSuchElementException错误的一则例子
- 【JAVA学习】Iterator迭代器导致的java.util.NoSuchElementException原因与解决方法
- "java.util.NoSuchElementException: No value present" 问题解决:重写hashCode 和 equals 方法
- 日常问题记录-- java.util.NoSuchElementException
- java.util.NoSuchElementException: No mapping for class sun.awt.AppContext
- java.util.NoSuchElementException解决办法
- java.util.NoSuchElementException: Timeout waiting for idle object
- java.util.NoSuchElementException: Timeout waiting for idle object
- Iterator错误:java.util.NoSuchElementException
- 解决sqoop java.util.NoSuchElementException
- 解决:Redis:java.util.NoSuchElementException: Unable to validate object at
- [Nutch2.3]调用generate的时候出现java.util.NoSuchElementException异常
- java.util.NoSuchElementException
- java.util.NoSuchElementException
- java.util.NoSuchElementException:Hashtable Enumerator 解决办法
- java.util.NoSuchElementException
- java.util.NoSuchElementException原因
- java中Exception in thread "main" java.util.NoSuchElementException
- Android编程:解决异常“java.util.NoSuchElementException”