I'm having a problem with adding objects to an arrayList in Java. I'm getting the following error when I run my code. This is a snippet of two of my files. I'd be much obliged were anyone to point out my error. Thanks, Joe
java.lang.NullPointerException at House.addRoom(House.java:18)at House.(House.java:36)
//ROOM CLASS
public Room () { Scanner scan = new Scanner(System.in); scan.useDelimiter("\n"); System.out.println("Enter description of room:"); description = scan.next(); System.out.println("Enter length of room:"); length = scan.nextDouble(); System.out.println("Enter width of room:"); width = scan.nextDouble(); } //HOUSE CLASS
public class House { private static ArrayList<Room> abode; public void addRoom (){ abode.add(new Room ()); } public House () { idNum = ++internalCount; Scanner scan = new Scanner(System.in); scan.useDelimiter("\n"); System.out.println("Enter address of house:"); address = scan.next(); System.out.println("Enter number of rooms:"); numRooms = scan.nextInt(); System.out.println("Enter type of house:"); houseType = scan.next(); for (int i=1; i<=numRooms; i++){ addRoom(); } } }