• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Class Cast Exception Problem

 
Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 79652
380
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
A magnificient life is loaded with tough challenges. En garde tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic