我想创建一个方法,它允许其他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