Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Java (http://www.programmingforums.org/forum17.html)
-   -   Help with object arrays (http://www.programmingforums.org/showthread.php?t=11850)

flamblob Nov 10th, 2006 6:31 AM

Help with object arrays
 
hey all, im trying to learn java and im having some trouble grasping arrays pointing to objects. All of my programs fail to compile with the same "cannot resolve symbol" error. I made a simplified script to show you what I am talking about. It gives me the symbol error and points to uno[count].theThing(). This would be the same in all my other programs regardless of the object name. I can't figure this out!!

:


class test {
public static void main(String[] args) {
int x=3; // the number of spots in the array
int x1; // a copy
theThing[] uno; // declare the array
uno = new theThing[x]; //give 3 spots to array
x1 = x; //copy x
while (x1>0) {
uno[x1] = new theThing();        //make the objects
x1--;

}// end while

tester(x); //go to the method
System.exit(0);

}// end main

static void tester(int count) {
while (count>0) {
System.out.println(uno[count].theThing()); //calls to theThing for theNumber
count--;
}// end while

}// end tester


}// end class test


class theThing {
int theNumber = 77;
int theThing() {
return theNumber;
}// end theNumber

}//end theThing


The Dark Nov 10th, 2006 6:43 AM

The uno variable is declared in main, you can't access it inside a different function.
You either have to pass it in, or make uno a static member of the test class.


All times are GMT -5. The time now is 11:23 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC