• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problems with java.util.NoSuchElementException: while using enumeration

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear all,

I have a problem. With this code:




This is the output I have received:

0class com.portal.pcm.FList
java.util.Hashtable$Enumerator@333128
1class com.portal.pcm.FList
java.util.NoSuchElementException: Vector Enumeration
at java.util.Vector$1.nextElement(Vector.java:305)
at com.tm.iCarePrime.eai.adapter.mcmb.MCMBSimplyForFun.main(MCMBSimplyForFun.java:127)

I don't know why this happening can you please point out to me. Thank you.


 
Rancher
Posts: 1776
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A guess - you try to call values.nextElement() twice in line #3 and lne #5. Can you try to make a single values.nextElement() and save it in a variable and use that?
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You call nextElement() twice inside the loop. Use a variable to store the results instead:
Also, please KeepItDown - not only in posts but also in subject lines.
 
Robinson Francis
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much to both John Jai and Rob Spoor.

I followed your advice and it ran without problems. Right now, I want to convert from the while loop to for each loop to loop through values. The problem now is that values is of type Enumeration.
Vaues was earlier initialized as below:




With services being a custom reference type for the system I am trying to interface with. The services reference type has getValueEnumerator() method which returns a Enumeration of values. So I am tied to Enumeration. Is there a way to use for each loop.

Thank you.
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can write a wrapper class that implements Iterator and delegates its methods to a backing Enumeration (with remove() throwing an UnsupportedOperationException). However, doing so just to iterate in a slightly different way is rather pointless.

If you want to get rid of the while loop, you can turn it into a for loop already:
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic