Hey how do I access an arraylist from another class? as in call an objects method inside of the arraylist but from the MasterControlPanel class?. Any help is greatly appreciated. Because the get(0) does not seem to be working.
//example
public class MasterControlPanel{
public static Building building = new Building();
public static void main(String[] args) {
building.rooms.get(0).*whatever*
}
}
public class Building
{
public static Rooms rooms[] = new Rooms[4];
private float outsideTemp;
ArrayList rooms = new ArrayList();
rooms.add(*new instance*);
rooms.add(*new instance*);
public Building() {
}
}
Add a getter:
Then you can do:
Aside: why aren’t you defining the type of your
Lists? Also, note that I’ve moved code into the Constructor for this class, and fixed name collisions. Also, why thestaticarray? Things to think about…Last note: added
floatto constructor to ensure it’s initialized.