I have classes A and B, I want to access a method from class A in class B but it isn't working, I'm getting the following message:
Exception in thread "main" java.lang.NullPointerException
The particular part that is causing this is when accessing ba
:
ba.getBalance() >= LIM
ba.debit(LIM);
I'm not sure what I'm doing wrong as I've created the private field and initialised it within main.
Class B:
public class B {
private A ba;
private long balance;
public B(long amount, A ba){
}
public boolean testCase(long amount){
//..
}
public long getBalance(){
return balance;
}
Class A:
public class A {
private long balance;
public A(long amount){
}
public boolean debit(long amount){
//.. simple arithmetic
}
public long getBalance(){
return balance;
}
Main
A aa = new BankAccount(amount1); // where amounts are user input
B bb = new GoCardAccount(amount2, aa);