Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Class Cast Exception

 
vasuma patel
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
vasuma patel
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the info. The error has gone after I restarted the App Server as suggested in the link.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic