I have 3 java source files.
Person.javaFriendsList.javaMyFriends.java
FriendsList contains an array list of objects of type Person and a method for adding a new friend to the list.
public class FriendsList{
ArrayList<Person> friendsList = new ArrayList<Person>(100);
// Constructor declaration of class
public FriendsList(ArrayList<Person> friendsList){
super();
this.friendsList = friendsList;
}
...
public void addFriend(Person friend){
friendsList.add(friend);
}
...
}
Now, in MyFriends.java I created a new array list of objects of type Person, I declared a new Person and I'm trying to add it to the list using the method addFriend(Person) but I'm getting an error "Method addFriend(Person) is undefined for the type ArrayList<Person>"
public class MyFriends{
public void main(String[] args){
ArrayList<Person> friendsList = new ArrayList<Person>(100);
Person f1 = new Person("Alice", "Anderson", "519-472-4910", "02", "19");
friendsList.addFriend(f1);
}
}
I tried all other methods defined in FriendsList.java but I get the same error message.
I understand that if the source files are in the same folder, the syntax to use a method from the other file is objectName.method(a).
What am I doing wrong?
(Sorry if I'm not asking it right, it's my first question)