The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Re: Run() method of runnable function has no access to data members?

When I backtrack, I see that the 'board' was set to a 'new Board', thus eliminating its null value.

I verified this by calling the printBoard method, via 'board', in the constructor (right after board = new Board()).

Hence, the board is no longer null.

Yet, when I enter the run function, it magically becomes null once again. I have no idea why. As a data member of my TTTClient class, I see no reason why initializing it in the constructor wouldn't initialize it for the rest of the class

Re: Run() method of runnable function has no access to data members?

Did you see that there is more than one variable named: board defined in the code? You assign a value to one of them. The other one's value stays at null. The local variable "shadows" the class level variable. A good IDE should report that with a warning because it is never a good idea to do that.
Solution: remove the definition of board from inside the method and use the one at the class level.

Re: Run() method of runnable function has no access to data members?

Nothing is magic. You created a new "board" variable in your constructor, thus "hiding" the class board variable. So the board variable that you initialize in your constructor is not the same one that is used in your run method.

EDIT: wow, everyone jumped all over this while I was typing, lol.

NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.

Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/