Home > Java > javaTutorial > Solution to error reporting when traversing values ​​in Java

Solution to error reporting when traversing values ​​in Java

黄舟
Release: 2017-08-13 09:31:36
Original
1955 people have browsed it

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())); 
      }
Copy after login

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)); 
      }
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template