wood burning stoves 2.0*
The moose likes Java in General and the fly likes Class Cast Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Class Cast Exception" Watch "Class Cast Exception" New topic
Author

Class Cast Exception

vasuma patel
Greenhorn

Joined: Mar 07, 2006
Posts: 15
I get a class cast exception on the same class. The exception message is

com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:160)
Caused by: java.lang.ClassCastException: com/A/B/SelectionsBean incompatible with com/A/B/SelectionsBean

This appears really wierd to me. I did some serach and came with this which is close to my problem but didn't quite understand the isuue.

http://www.jspwiki.org/wiki/A2AClassCastException

Appreciate any inputs.

Thanks in advance

Vasuma
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
If you load the same class file through two class loaders, Java considers them to be different classes in memory. This might be the problem.

Java has a family of ClassLoaders that load the .class files from disk or jars or remote servers or wherever they are. There are a special loaders for starting up an application but by the time a simple application starts running your code it has put a class loader in place for you and all of your classes will be loaded by the same class loader. Your casting problem shouldn't come up.

But in more complex systems, especially in frameworks like the servlet or EJB containers, there may be more class loaders floating around. The whole setup is framework-specific ... one environment might be very different from another. In EJB land I once had to get the classloader that loaded "this" class in order to load another because of differences in the classpaths.

Here's a Classloader Paper from IBM ... I think it's one that I read a while ago and thought was pretty good. See if it helps.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
vasuma patel
Greenhorn

Joined: Mar 07, 2006
Posts: 15
Thanks for the info. The error has gone after I restarted the App Server as suggested in the link.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Class Cast Exception