1

So I'm working on creating the game of Monopoly, I'm in way over my head but I'm willing to learn. Anyways my problem is that I create the array with size based on user input (holds the different Player objects) but when I try accessing the index of the array (those objects) from another class or even a different object, I get the error "cannot find symbol - variable arr(the array at hand)" How can I gain access to the data in these Players? If my question is unclear just ask and I'll restate it. (error is in last line of PlayerOrder)

Player[] arr; was outside of the scope of other objects, meaning it was specific to the object I declared in so I couldn't access it's info using another method.

To fix this, I added..

private Player[] arr;

as seen here..

private Player[] arr;
import java.util.Scanner;
import java.util.Random;
public class Launcher
{
PairOfDice myDice = new PairOfDice();
private Planet myTest;
private PlanetInfo myPlanetInfo;
private int p1;
private int p2;
//more code
  • 2
    You should familiarize yourself with scope of variables. – Sotirios Delimanolis Nov 29 '13 at 00:09
  • How does code code snippet relate to the question? – John3136 Nov 29 '13 at 00:09
  • Sotirios Delimanolis I'm still learning, that's why I brought my question here. Can you please explain the issue? Is the array's contents out of the scope of other objects? Please explain. – Brothah Heffay Nov 29 '13 at 00:13
  • why do you put method and constructor codes behind the scenes. no abstraction please... – Prashant G Nov 29 '13 at 00:13
  • Per @SotiriosDelimanolis try this: http://www.java-made-easy.com/variable-scope.html – Taylor Nov 29 '13 at 00:43
  • Note that an "index" is a numeric value you use to select an array entry. The thing you access with that index is an "element" or "entry" of the array. I suspect you're trying to access the elements of an array. – Hot Licks Nov 29 '13 at 03:35

0 Answers0