• Post Reply Bookmark Topic Watch Topic
  • New Topic

ClasscastException

 
Anuj Kumar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using EJB2.0 .I am executing a query that first populate data into a bean and then add this bean into a list and i am returning this list from a business method in the stateless SessionBean. Everything is fine it is executing the query and returning the list containing the beans but when i used to cast the list.get(i) to my bean type then it throwing ClasscastException in my Action class in the web client .Bean class id serializable..?? please help
 
akhilesh pandey
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please check the type in which you are getting the list.get(i).
In java ClasscastException is thrown when you wrongly cast one object to other type.
For example yesterday I was trying to cast Enumeration object into Vector and I was also gettng the same exception.
 
Anuj Kumar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks akhi i am uing the same type of class to cast it but still it is throwing this problem
 
Amit M Tank
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you post the full stack trace of the exception here?
 
Bill Shirley
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And perhaps some of the code.
Sounds like "you're going the wrong way!"
("How does he know where we're going?")
[gratuitous Planes, Trains, and Automobiles quote]


it also sounds like you're using Java 1.4, or not using generics in Java 5+
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"akhi tronics",
Welcome to JavaRanch!

We're pleased to have you here with us here on the ranch, but there are a few rules that need to be followed. One is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious. Initials are OK for the first and middle names but not the last. You can change it here
[ June 09, 2008: Message edited by: Ben Souther ]
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are certain that the class types are identical, then there must be a classloading problem. If you have one application, then build a single EAR file containing your WAR and EJB files. This will work because the EJB server will load the EJB classes before the web classes, thus ensuring that the EJB classes will be visible to the web application and not loaded twice.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!