Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I'm having a little trouble with a reference to a variable created from a static method.
public class Main {
static ArrayList rings = new ArrayList();
/** Creates a new instance of Main */
public Main() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
initTowers();
initRings(Integer.parseInt(JOptionPane.showInputDialog("Number of rings:")));
solve();
}
public static void initTowers(){
Tower src = new Tower(1);
Tower aux = new Tower(2);
Tower des = new Tower(3);
}
public static void initRings(int numRings){
for(int i=1; i<= numRings; i++){
rings.add(new Ring(i));
}
for(int i=numRings; i>= 1; i--){
((Ring)(rings.get(i))).moveTo(src);
}
}
public static void solve(){
}
}The error is on this line:
((Ring)(rings.get(i))).moveTo(src);
Using Netbeans 5.0, the line creates an error that basically tells me there is no such variable src. I've tried to typecast it as a Tower, but to no avail. Any help would be greatly appreciated.P.S. - they should really let you use the "code" tags, especially in the Programming forum.
Any help would be greatly appreciated... any help... at all... about anything... please?

If you want to send me the whole NB project folder I'll take a look for you. I can't stand looking at code on the forum and I suspect there might be an error in another one of your classes.
Zip and e-mail me the project if you want.
Alert me after you respond otherwise I'll forget to come back.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |