
-----------------------------------
Ashi_Mashi2
Sat Jan 07, 2006 2:33 am

objects into a Vector?
-----------------------------------
hi every1....

I want to store an array of objects (i.e. my own classes) into an array and retrieve the address as needed...does anyone have any ideas?

i tried using a vector array, it stores fine, but, when I want to retrieve it using .elementAt (x) it wont return the object. 


e.g. 
Vector v = new Vector();
Test t = new Test();
v.addElement(t);


ERROR: Test t2 = v.elementAt (0);

thx.

-----------------------------------
wtd
Sat Jan 07, 2006 2:41 am


-----------------------------------
Since you're using 1.4.2, you'll need to insert a cast.  You see, when an object is stored in a Vector, it's stored as simply an object of class Object.  Now, you assign it to a variable of class Test.  This is now good since an Object is not necessarily a Test object.

Test t = (Test)v.elementAt(0);

-----------------------------------
Ashi_Mashi2
Sun Jan 08, 2006 1:18 pm


-----------------------------------
thankx..works perfect:)
