Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

getting ClassCastException

 
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
 
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.
 
author
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
 
ranger
Posts: 17346
11
Mac IntelliJ IDE 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
 
It sure was nice of your sister to lend us her car. Let's show our appreciation by sharing this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic