The Artima Developer Community
Sponsored Link

Java Answers Forum
ClassCastException

1 reply on 1 page. Most recent reply: Oct 25, 2003 11:06 AM by R. Pasay

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
R. Pasay

Posts: 2
Nickname: hcblue
Registered: Oct, 2003

ClassCastException Posted: Oct 25, 2003 8:30 AM
Reply to this message Reply
Advertisement
Hi-

Umm... I'm having trouble with the piece of code below. I've been trying for hours and still couldn't get it to run properly.

Iterator iter = this.iterator();
while (iter.hasNext()) {
  Node currentNode = (Node) iter.next();
  City currentCity = (City) (currentNode.getValue());
}


currentNode.getClass() returns class Node as expected.
getValue() returns an Object.
currentNode.getValue().getClass() returns a class City, also as expected.

But the problem is, City currentCity = (City) (currentNode.getValue()); returns the following runtime error:

Exception in thread "main" java.lang.ClassCastException: java.lang.String


Is there something obvious I'm not aware of that someone could point out?
Thanks.


R. Pasay

Posts: 2
Nickname: hcblue
Registered: Oct, 2003

Re: ClassCastException Posted: Oct 25, 2003 11:06 AM
Reply to this message Reply
Got the problem resolved.
It was a glitch in the LinkList.

~R~

Flat View: This topic has 1 reply on 1 page
Topic: Linking a Style Sheet to a Servlet Previous Topic   Next Topic Topic: Session Tracking

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use