ClassCastException

I'm trying to send multiple textarea values from jsp to be inserted into database. However the textarea values are not received in the Action class properly. I get ClassCastException when trying to insert the data into database.

Whats the workaround ?

Please see the file attached for details
ClassCastException.txt
cofactorAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
objectsConnect With a Mentor Commented:
try changing your bean to


private List<String> itemDescription;

public List<String> getItemDescription() {
      return itemDescription;
}
public void setItemDescription(List<String> itemDescription) {
      this.itemDescription = itemDescription;
}
0
 
Dejan PažinHead of SW DevelopmentCommented:

It looks like you are trying to cast array of Strings into String. Try casting to Stirng[].
0
 
Sathish David Kumar NArchitectCommented:
Y ur casting that in to string ?
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
cofactorAuthor Commented:

>>>Y ur casting that in to string ?

If I dont do , then I get compile error
in java.sql.PreparedStatement cannot be applied to (int,java.lang.Object)
    [javac]                             ps.setString(3,cvo.getItemDescription().get(k));
0
 
cofactorAuthor Commented:
>>>It looks like you are trying to cast array of Strings into String. Try casting to Stirng[].

please see the prints I put in the attached text file.

My objective is,  I  want to get the String values entered in the textarea and  insert  into database. What would be  the correct code ?
0
 
Sathish David Kumar NArchitectCommented:
try with toString() method
0
 
Dejan PažinHead of SW DevelopmentCommented:
Where you call this:

(String)cvo.getItemDescription()

Open in new window


You should actually call:
((String[])cvo.getItemDescription())[i]

Open in new window


where i is the index of your text item.
0
 
cofactorAuthor Commented:
object is right .  That works . Awesome!

I just put the generic as object suggested  and the error vanished....excellent.

But why the explicit casting did not work ?  Why the generic worked but explicit cast failed ?

I'm using jdk 1.6 .
0
 
objectsCommented:
> But why the explicit casting did not work ?  Why the generic worked but explicit cast failed ?

because it wasn't a list of strings.
Without the generics it cannot accurately determine what the type of object in the list is
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.