• Post Reply Bookmark Topic Watch Topic
  • New Topic

getting ClassCastException

 
Anurag Mishra
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code is compiling finely.But at runtime it is throwing
ClassCastException
Plz help me out.

vec.addElement(new DataInfo(r, description, values));
}
}
DataInfo rv[]=new DataInfo[vec.size()];
rv=(DataInfo[])vec.toArray();
return rv;
} catch (Exception e) {
throw new DatabaseException(UNEXPECTED + e);
}
}
This exception is thrown when an Object is incompatible with the elements in Vector.
Plz help me out to get rid out of this problem..
Anurag Mishra
 
Lance Finney
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was running into this, too. You have to use a different version of vec.toArray(). Check the API for a version that takes the array you want to copy the values into.
 
Anurag Mishra
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I could'nt able to use the second version plz tell me how to apply (Object[])vec.toArray(Object a[]) in my code. Or if there is any other idea behind it plz let me know.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stick your DataInfo[] into the method.
- Peter
 
Anurag Mishra
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter
Plz be more specific about your saying.I want little more expalnation regarding your answer.
Anurag
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
He means put
(DataInfo[])vec.toArray(rv);

Something like that.

Mark
[This message has been edited by Mark Spritzler (edited October 05, 2001).]
 
Anurag Mishra
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mark This is exactly what i want.
Anurag
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!