error

Hey guys I am a new java programmer.......I have a class firmobj abd a vector vec1....here I have created a firm object and assigned the vector vec1 to it.....I have type casted it as below. But I got the following error.

firmobj firm = (firmobj) vec1;

error: the type of the expression must be an array but resolves to vector.

[354 byte] By [saranatora] at [2007-10-3 2:14:05]
# 1
If vec1 is not of the type firmobj then you can't cast to it. What is it that your trying to do? Can these objects just both be lists?
zadoka at 2007-7-14 19:12:55 > top of Java-index,Java Essentials,New To Java...
# 2

Below is a part of the code ......vec1 has been declared an array and firmobj is a class with getters and setters to make an object.

Vector vec1 = new Vector();

while(table1.next()) {

firmobj1 firm = new firmobj1();

firm.setFirmID(table1.getInt("org_id"));

firm.setDsclCode(1);

firm.setCount(table1.getInt("counts"));

vec1.add(firm);

}

for(int i=0;i<vec1.size();i++) {

firmobj1 firm = (firmobj1) vec1;

}>

saranatora at 2007-7-14 19:12:55 > top of Java-index,Java Essentials,New To Java...
# 3
Please use code tags.Where is the class for firmobj1? Does it extends something else?
zadoka at 2007-7-14 19:12:55 > top of Java-index,Java Essentials,New To Java...
# 4

Vector vec1 = new Vector();

while(table1.next()) {

firmobj1 firm = new firmobj1();//firmobj is a class in the same package and extends nothing

firm.setFirmID(table1.getInt("org_id"));//table1 is resultset variable whih extracts data from DB table

firm.setDsclCode(1);

firm.setCount(table1.getInt("counts"));

vec1.add(firm);// adds the object firm to the vector

}

for(int i=0;i<vec1.size();i++) {

firmobj1 firm = (firmobj1) vec1;//trying to display the data from vector using the get methods inthe

// firm obj. but gives ann srror as mentioned in the first post

}>

saranatora at 2007-7-14 19:12:55 > top of Java-index,Java Essentials,New To Java...
# 5
for( int i=0; i<vec1.size(); i++ ) {firmobj1 firm = (firmobj1) vec1.get(i);} >
masuda1967a at 2007-7-14 19:12:55 > top of Java-index,Java Essentials,New To Java...
# 6
done ....thanks i appreciate the help
saranatora at 2007-7-14 19:12:55 > top of Java-index,Java Essentials,New To Java...
# 7
You can not cast vector into your object.You need to cast element of vecttor by get(index) in the for loop
masuda1967a at 2007-7-14 19:12:55 > top of Java-index,Java Essentials,New To Java...