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

Solution to error reporting when traversing values ​​in Java

黄舟
黄舟Original
2017-08-13 09:31:361938browse

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!

Statement:
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