So i have to write a program that designs a basic Home CAD System. The user will be able to build a house, add/remove rooms and items, etc. I have began writing the program and all seems gravy, i decided to use an ArrayList for the list of rooms the user adds but i am unsure of how to add to this ArrayList. We have been provided with a test harness class which tests to see if our program functions correctly, and at the moment the program successfully "adds" the rooms, but when i try to retrieve the information about the added rooms i am faced with a nullpointerexception, which i believe is because i am not using the ArrayList properly. Here is some of my code which i believe may be the problem:
private static RoomReference ref1 = new RoomReference(1, 1, 1);
//creating the first room
System.out.print("Creating first room...");
model.addRoom(new RectangularRoom(ref1, "RoomA", 3, 4, 2));
// find first room
System.out.print("Finding first room with getRoom()...");
if (failureCheck(model.getRoom(ref1).toString().equalsIgnoreCase(
"1,1,1:3,4,2:RoomA::"), true))
return false;
//array stuff
ArrayList<Room> room = new ArrayList<Room>();
public void addRoom(Room room) {
room.add(new RectangularRoom(ref1, "Room1", 4, 3, 2));
}
Thanks in advance for your help.