This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Class Cast Exception Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Class Cast Exception Problem" Watch "Class Cast Exception Problem" New topic
Author

Class Cast Exception Problem

Abiodun Adisa
Ranch Hand

Joined: Jan 17, 2002
Posts: 495
I am receiving the following error whenever i am trying to cast to some other object


My question is am i suppose to cast to org.apache.myfaces.context.servlet.AbstractAttributeMap which is what i did and why is there a $EntrySetEntry after AbstractAttributeMap
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38424
    
  23
Which exception are you getting? Is it a ClassCastException?

The bit about $EntrySetEntry means there is an inner or nested class inside AbstractAttributeMap called EntrySetEntry. Most Map implementations have EntrySet inner or nested classes. I think nested, but I am not sure.

You cannot cast to "some other object." You can only cast an object reference to a class which the object is already an instance of. So if you are casting ((Foo) myObjectReference.)bar() it means that myObjectReference must already be an instance of Foo (and Foo must have a method called bar()). If whatever you are casting doesn't refer to an instance of that class, the JVM will be unable to execute the cast and you get the ClassCastException.

But you haven't actually told us which Exception you are getting.
 
wood burning stoves
 
subject: Class Cast Exception Problem