iterator does not return objects properly

  • Thread starter nooneinparticular314159
  • Start date
N

nooneinparticular314159

Whenever I do:

Iterator KeyIterator = KeySet.iterator();
while (KeyIterator.hasNext()){
Attack ReturnedAttack = (Attack)
KeyIterator.next();

I get an error, either:
Exception in thread "main" java.lang.ClassCastException:
java.lang.String
at geolocation.Main.main(Main.java:141)
The process tried to write to a nonexistent pipe.

or a no such object error, even though I can verify that there are
objects in the object being iterated on.

Any idea why?

Thanks!
 
M

Missaka Wijekoon

Whenever I do:

Iterator KeyIterator = KeySet.iterator();
while (KeyIterator.hasNext()){
Attack ReturnedAttack = (Attack)
KeyIterator.next();

I get an error, either:
Exception in thread "main" java.lang.ClassCastException:
java.lang.String
at geolocation.Main.main(Main.java:141)
The process tried to write to a nonexistent pipe.

or a no such object error, even though I can verify that there are
objects in the object being iterated on.

Any idea why?

Thanks!
How about a little background? What version of the JDK? Is it Sun's?
What OS? How about a little code that can reproduce the problem?

-Missaka
 
A

Alun Harford

Whenever I do:

Iterator KeyIterator = KeySet.iterator();
while (KeyIterator.hasNext()){
Attack ReturnedAttack = (Attack)
KeyIterator.next();

I get an error, either:
Exception in thread "main" java.lang.ClassCastException:
java.lang.String

The Object in KeySet, that the iterator returns, is not of class Attack.

Alun Harford
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,017
Latest member
GreenAcreCBDGummiesReview

Latest Threads

Top