0
我有一個foreach循環遍歷每個首選客戶,並總結他們的餘額以創建其總資產。但是,每次查看客戶對象時,都會將其評估爲空。 PreferredCustomer是抽象類Customer的一個子類。我假設我沒有正確地做foreach循環,但我不知道我做錯了什麼。由於某種原因,我的客戶對象爲空。
public static void getBalance() {
for(Customer customer: preferredCustomers){
ArrayList<Account> al = customer.getAccountList();
for(Account account: al){
totalAssets+=account.getBalance();
//balance = account.getbalance();
}
customer.setBalance(totalAssets);
}
}
另外,Arraylist AccountList是每個客戶的賬戶對象列表。
您的循環是正確的,它最有可能是preferredCustomers包含空值。 – rodion
你將不得不在你創建/填充'ArrayList'的地方顯示代碼片段。 – Baz
您的getBalance函數沒有收到餘額。 – Wug