When I add a member object from a class called Member to an array list "members = new ArrayList();" within a class called Library, and then try and print off a list of data within the array list I get an error message in the print out:
Member@12eb9b8
Member@172d568
The method I am using to add the member objects to the array list is:
public void joinMember(Member joinMember)
{
members.add(joinMember);
}
And the method I am using to print out all of the data within the array list is:
public void listMembers()
{
for(Member joinMember : members){
System.out.println(joinMember);
}
}
Can anyone please help? I have checked over the code and I cannot work out why it's not printing out the correct data.
That is not an error, it seems to be the value of instantiated object references. If you want to print what is inside, you either need to access something from the object to print, like
or
Add a
toString()
method to the class.