• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Urgent please.....

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Sorry.I didn't get the result using conversion of vector to integer.
My problem is that ,I am getting values from the database.Following is the code:
while(rs1.next())
{
vectorx1.add(rs1.getString(1));
vectory1.add(rs1.getString(2));
vectorw1.add(rs1.getString(3));
vectorh1.add(rs1.getString(4));
}
where vectorx1,vectory1,vectorw1 and vectorh1 are of type Vector.Here I made the conversion is like this:
for(int pn=0;pn<=vectorx1.size();pn++)
{
x1=Integer.parseInt((String)vectorx1.get(pn));
y1=Integer.parseInt((String)vectory1.get(pn));
w1=Integer.parseInt((String)vectorw1.get(pn));
h1=Integer.parseInt((String)vectorh1.get(pn));
}
where x1,y1,w1 and h1 are of type "int".
The other way also I tried.i.e., :
while(rs1.next())
{
vectorx1.add(new Integer(rs1.getInt(1)));
vectory1.add(new Integer(rs1.getInt(2)));
vectorw1.add(new Integer(rs1.getInt(3)));
vectorh1.add(new Integer(rs1.getInt(4)));
}
and the conversion to integer is made like this:
for(int pn=0;pn<=vectorx1.size();pn++)
{
x1=((Integer)vx.elementAt(pn)).intValue();
y1=((Integer)vy.elementAt(pn)).intValue();
w1=((Integer)vw.elementAt(pn)).intValue();
h1=((Integer)vh.elementAt(pn)).intValue();
}
Using these two ways I am getting an exception "ClassCastException". But I didn't understand what is the problem of my code.You please urgently give me an idea.I need a solution for this very urgently.If you give it today if possible I am greatly thankful to you.
Thank you.
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I only see one problem with your code myself, and it has nothing to do with the ClassCastException.
for(int pn=0;pn<=vectorx1.size();pn++)
should be:
for(int pn=0;pn < vectorx1.size();pn++)
or you will get an ArrayOutOfBoundsException
[This message has been edited by Randall Twede (edited February 03, 2001).]
 
reply
    Bookmark Topic Watch Topic
  • New Topic