我想創建一個方法,它允許其他Account
被添加到一個集合:「無法找到符號 - 方法添加」使用ArrayList中
import java.util.*;
import java.util.ArrayList;
/**
* The Account list if the grouping of all the accounts for customers in the system.
*
* @author
* @version 1.0
*/
public class AccountList
{
// This is the ArrayList being declared
private ArrayList<Account> accounts;
/**
* Constructor for objects of class AccountList
*/
public AccountList()
{
//This is the ArrayList being initialised in a constructor.
accounts = new ArrayList<Account>() ;
}
/**
* This method will allow a new account to be added to the system.
*
* @param accounts the accounts in the system.
*/
public void addAccount(Account accounts)
{
accounts.add();
}
}
的問題是,它無法找到方法add
上addAccount
部分,即使在類的頂部導入了ArrayList
類。我是Java新手,所以任何幫助將不勝感激!
'ArrayList'不具有'不採取任何參數add'方法。 – JonK 2014-10-31 09:45:26
我認爲你曾經喜歡過去的「陰影」。您的'accounts.add()'操作在類的accounts字段上是_NOT_,但在methods參數上。 – Korashen 2014-10-31 09:47:47