I'm trying to use a class ("Screen") to handle all instances of System.out.print in my other classes. However I am getting a null pointer exception from my main method when I try to run my code to test it it.
I can't figure out what exactly is causing this error, any tips would be appreciated.
Main Class
public class AtmTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
//Screen.displayMessage(null);
AtmTest test = new AtmTest();
}
public AtmTest(){
//write way to start all processes
new ATM();
}
}
This is the ATM class where I am first tyring to call the Screen class to display a message to the console, and where my code stops running.
public class ATM {
private boolean userAuthenticated;
private int currentAccountNumber;
private static final int BALANCE_INQUIRY = 1;
private static final int WITHDRAWAL = 2;
private static final int DEPOSIT = 3;
private static final int EXIT = 4;
private Keypad keypad;
private Screen screen;
private BankDatabase bankDatabase;
public ATM(){
//new Screen();
//screen.displayMessage("hey");
run();
}
public void run(){
screen.displayMessageLine("Welcome!");
authenticateUser();
displayMainMenu();
performTransactions();
}
This is the screen class that is supposed to control all outputs for the program.
public class Screen {
public Screen(){
}
public void displayMessage(String a){
System.out.print(a);
}
public void displayMessageLine(String a){
System.out.println(a);
}
public void displayDollarAmount(double a){
System.out.println("$" + a); //make to two decimal places
}