这是一个家庭作业问题,当我运行测试仪时它给了我空指针异常。错误似乎在我的行中
balance[i]=InitialBalance;
public class Bank
{
private BankAccount[] accounts;
private double [] balance;
int NumbersOfBankAccount;
double InitialBalance;
public Bank (int x, double y )
{
NumbersOfBankAccount = x;
InitialBalance = y;
}
/**
* This method will get balance of specified bank account.
*/
public double getBalance(int index)
{
for(int i = 0; i <NumbersOfBankAccount; i++)
{
balance[i]=InitialBalance;
}
System.out.println(balance);
return balance[index];
}
}