• 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: 17278
6
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic