I'm trying to run "loadProgram" located in the motherboard class through the "Room" class. I typed
theRoom.getTheComputer().getMotherboard().loadProgram("Windows"); But I get
Exception in thread "main" java.lang.NullPointerException at Main.main(Main.java:12)<5 internal calls>
Main
public class Main {
public static void main(String[] args) {
Keyboard theKeyboard = new Keyboard("Test1", "Razer");
Motherboard theMotherboard = new Motherboard("RX-58","Asus",4, 6, "v2.44");
Computer theComputer = new Computer(theKeyboard, theMotherboard);
Room theRoom = new Room(theComputer);
theRoom.getTheComputer().getMotherboard().loadProgram("Windows");
}
}
Room
public class Room {
private Computer theComputer;
public Room(Computer theComputer) {
this.theComputer = theComputer;
}
public Computer getTheComputer() {
return theComputer;
}
}
Computer
public class Computer {
private Keyboard theKeyboard;
private Motherboard motherboard;
public Computer(Keyboard theKeyboard, Motherboard theMotherboard) {
this.theKeyboard = theKeyboard;
}
public Keyboard getTheKeyboard() {
return theKeyboard;
}
public Motherboard getMotherboard(){
return motherboard;
}
}
Motherboard
public class Motherboard {
private String model;
private String manufacturer;
private int ramSlots;
private int cardSlots;
private String bios;
public Motherboard(String model, String manufacturer, int ramSlots, int cardSlots, String bios) {
this.model = model;
this.manufacturer = manufacturer;
this.ramSlots = ramSlots;
this.cardSlots = cardSlots;
this.bios = bios;
}
public void loadProgram(String programName){
System.out.println("Program " + programName + " Is now loading... " );
}
public String getModel() {
return model;
}
public String getManufacturer() {
return manufacturer;
}
public int getRamSlots() {
return ramSlots;
}
public int getCardSlots() {
return cardSlots;
}
public String getBios() {
return bios;
}
}