View Single Post
  #3 (permalink)  
Old 03-13-2008, 03:54 PM
aibtus's Avatar
aibtus aibtus is offline
Member
 
Join Date: Mar 2008
Location: Randburg, South Africa
Posts: 9
aibtus is on a distinguished road
Send a message via Yahoo to aibtus Send a message via Skype™ to aibtus
Quote:
Originally Posted by markyoung1984 View Post
I am very new to Java.

I have a List called siteList, which has about 65 objects of type Site. I have a for loop in which I wish to iterate through the List and call a function (test) from each Site object. I'm but quite sure how to do this. So far I have:

Code:
for (int i=0;i<siteList.size();i++) { siteList.get(i).test(3,3); }
The compiler states that it cannot resolve symbol for test. Any suggestions?
well, for starters...
Code:
siteList.get(i)
will return an Object.... a generic object...Every class in Java is an Object and I can tell you this "test" is not a java object instance variable......

It's specific to your class maybe...a particular class ...not a generic 'Object' class.
Do something like this
Code:
((MyClass)siteList.get(i)).test(3,3);
Cas the returned object to MyClass --- your particular class. and the call the in stance variable on the cast
Reply With Quote