-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Classcast exception while type casting DTO into formbean
PostPosted: Sun Sep 27, 2009 5:40 am 
Newbie

Joined: Mon Aug 31, 2009 1:45 am
Posts: 12
we are getting a class cast exception while casting DirectorDTO into CompanyForm

List DirectorList = companyform.getDirectorData(); // returns directorDTO

(CompanyForm)DirectorList.get(i).ischecked()==true //this line shows class cast exception.



please help me to get this resolved


Top
 Profile  
 
 Post subject: Re: Classcast exception while type casting DTO into formbean
PostPosted: Sun Sep 27, 2009 6:41 am 
Senior
Senior

Joined: Mon Jul 07, 2008 4:35 pm
Posts: 141
Location: Berlin
Hi maheshwari_siddharth,

how are we supposed to figure out this issue if we do not have any information on your data types and how they are related? Magic? Sorry, my crystal ball is currently in repair...

But I believe though that
Code:
DirectorList.get(i).ischecked()==true
is not returning a class of any kind rather than a boolean.

BTW, this does more look like a Java question than a Hibernate one.

CU
Froestel

_________________
Have you tried turning it off and on again? [Roy]


Top
 Profile  
 
 Post subject: Re: Classcast exception while type casting DTO into formbean
PostPosted: Sun Sep 27, 2009 9:18 am 
Newbie

Joined: Mon Aug 31, 2009 1:45 am
Posts: 12
thanks Froestel

we have 5 directors in a table which we display in the JSP through logic iterate

now we want to delete 2 directors

we have a checkbox against each director where we select 2 and press delete button.

now we want to check in the action which two are selected out of five

this is an objective and for this we are using this code

List DirectorList = companyform.getDirectorData(); // returns directorDTO having all the directors info

Company form having a isChecked property having setter getter method

(CompanyForm)DirectorList.get(i).ischecked()==true //now we are checking which two lines are selected

but above line shows class cast exception


Top
 Profile  
 
 Post subject: Re: Classcast exception while type casting DTO into formbean
PostPosted: Sun Sep 27, 2009 10:06 am 
Senior
Senior

Joined: Mon Jul 07, 2008 4:35 pm
Posts: 141
Location: Berlin
Hi maheshwari_siddharth,

still you provide no information on your class structure neither do you post the stack trace of your exception - how is someone supposed to help if you do not provide the necessary information???

So another guess from the following code line:
Code:
(CompanyForm)DirectorList.get(i).ischecked()==true //now we are checking which two lines are selected

It looks like the elements of DirectorList need to be instances of the CompanyForm class to simply be able to cast. If that is case you still might have some syntax error since your cast does not seem to do what you intent. Try enclosing (CompanyForm)DirectorList.get(i) in round brackets:
Code:
((CompanyForm) DirectorList.get(i)).ischecked()==true //now we are checking which two lines are selected

This will NOT get rid of your CCE - I do not believe that the elements in your DirectorList are actually of type CompanyForm. That's not very likely. In Java you can only cast to types that are above the actual in the same class hierarchy.

... and still this is a Java question, no Hibernate question. You ended up in the wrong forum.

CU
Froestel

_________________
Have you tried turning it off and on again? [Roy]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.