![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2006
Posts: 1
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#2 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 824
Rep Power: 4
![]() |
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. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Level Editor | frankish | Show Off Your Open Source Projects | 47 | Jul 10th, 2006 6:57 PM |
| Library problem creating Direct3d Object | Kilo | C++ | 9 | May 30th, 2006 8:48 AM |
| Arrays or Vectors? | can342man | C++ | 2 | Apr 20th, 2006 3:57 PM |
| Arrays in PHP | MrMan9879 | PHP | 6 | Jan 12th, 2006 9:18 PM |
| references passed through parameters, do they copy the object or reference the orig? | cypherkronis | Python | 1 | Jun 30th, 2005 7:38 PM |