尝试打印 arraylist 时出错

Error while trying to print out arraylist

我正在恢复的错误是 "void type is not allowed here " 我将如何修复此错误以打印出我的数组列表。

 import java.util.ArrayList;



public class Library
{


    private ArrayList<Member>listOfMembers;
    public Library()
    {
        listOfMembers = new ArrayList<Member>();
    }
    public void storeMember(Member Member)
    {
        listOfMembers.add(Member);
    }
    public int numberOfMembers()
    {
        return listOfMembers.size();
    }

    public void listMembers()
   {
   for (int item=0; item<listOfMembers.size(); item++ ) {
     Member m = listOfMembers.get (item);
    System.out.println(m.GetWholeName());
        }
    } 


}

这是我的会员class,以备不时之需

class Member
{
    // The fields.
    private String firstname;
    private String lastname;
    private Integer number;
    private Integer id;

    /**

     hehe
     */
    public Member(String firstName, String lastName, Integer telNumber, Integer memberId)
    {
        firstname = firstName;
        lastname = lastName;
        number = telNumber;
        id = memberId;

    }


    // Add the methods here ...
    public void GetWholeName(){

    System.out.println(firstname + (" ") + lastname);

}
}

我正在尝试使用我的库 class

中的数组列表来打印我的成员 class 的名字和姓氏

您正在尝试打印 m.GetWholeName() 的结果,但 return 无效。将 GetWholeName 更改为 return a String,或者简单地调用 GetWholeName 因为它已经将名称打印到标准输出,尽管该行为与名字会暗示。

public String GetWholeName() {

    return firstname + " " + lastname;

}

在成员 class 中更改为:

System.out.println(firstname + (" ") + lastname);

对此:

return firstname + " " + lastname;