Forums Register Login

Class Cast Exception

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Thanks for the info. The error has gone after I restarted the App Server as suggested in the link.
Time flies like an arrow. Fruit flies like a banana. Steve flies like a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1227 times.
Similar Threads
Wiki recommendations
Servlet access to MBean in JBoss
Using Stored procedure in spring with hibernate
J2EE wikis?
Opinions on JSP Wiki
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 04:22:26.