• Post Reply Bookmark Topic Watch Topic
  • New Topic

ClassCast Exception Pl. help

 
Boon Subra
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am trying to put the vector elements in array.Why do I get the class cast Exception.
Vector vclient = clinfo.fetchCompanyClient(2);
System.out.println(vclient);
String allClient[] = new String[vclient.size()];
Enumeration eclint = vclient .elements();
int i=0;
while(eclint.hasMoreElements())
{
allClient[i] =(String)eclient.nextElement();
System.out.println(allClient[i]);
i++;
}

Pl. help me urgently.
System.out.println(vclient);
I am able to print the vector.
Thanks ,
Bhuvana
 
Murali Nanchala
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bhuvana,
Why bother with the iterations when you know what kind of Objects are stored in the Vector.
Just use the following if you will store only Strings in the Vector.
 
Andy Bowes
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Class Cast Exception would seem to indicate that the items in the vector are NOT Strings.
You might well be able to print the contents of the vector since this will use the toString() method on the objects in the vector. It does not mean that all of the elements in the vector are Strings.
 
suresh guru
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
allClient[i] =(String)eclient.nextElement();
The root cause is the Vector has some Objects tat are not castable to String
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!