"Cannot find symbol - method add" mit ArrayList

Ich versuche, erstellen Sie eine Methode, die es erlaubt ein weiteres Account zu werden, zu einer Kollektion Hinzugefügt:

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();

    }
}

Das problem ist, dass es nicht finden können, die Methode add auf die addAccount Abschnitt sogar mit der ArrayList Klasse importiert werden, die an der Spitze der Klasse. Ich bin neu in Java, also jede Hilfe wäre sehr geschätzt werden!

  • ArrayList keine add Methode nimmt keinen Parameter.
  • Ich denke, Sie encoutered die gute alte "Shadowing". Ihre accounts.add() - Betrieb NICHT auf Ihre accounts Feld der Klasse, sondern auf die Methoden-parameter.
InformationsquelleAutor Patterrz | 2014-10-31
Schreibe einen Kommentar