我正在恢復的錯誤是「void type不允許在這裏」,我將如何解決這個錯誤以打印出我的數組列表。嘗試打印陣列列表時出錯
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 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);
}
}
我試圖通過使用一個數組列表,打印我的成員類的姓和名我的圖書館類
感謝您這解決了它 – Hmed 2015-01-15 19:00:23