Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Class Cast Exception  RSS feed

 
Rahul Patel
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

There seems to be a problem..I keep getting this java.lang.ClassCastException but the servlet is working fine.

I get this error at two locations:

1) doPost(request, response);

2) Object o = ctx.lookup("<path of bean>");

I am in need of suggestions..please do

Thanks,
Rahul
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

Please don't post the same question to more than one forum; see our explanation here. I've deleted the other copies of this thread.

The code you're showing couldn't possible cause ClassCastExceptions, as there are no casts on these lines. Show us the actual stack trace you're getting, and the exact, real, cut-and-paste lines of code indicated at the top level of the stack trace.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The information you have provided is not enough. Can you please send the stack trace ?
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think while casting o you might be getting the cast exception.However the stacktrace would give you more information in this front.

Object o = ctx.lookup("<path of bean>");
 
Srinivasan thoyyeti
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rahul Patel,

This can also happen if you are expreimenting with you own Object class.
try check with java.lang.Object instead.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tracking down ClassCastExceptions is not a servlet specific issue.
It is a general Java issue.
Moving to Java in General (Beginner).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!