先定义Meeting
public class Meeting implements Serializable{
private int meetingID;
private String meetingName;
private List<UserDTO> members=new ArrayList<UserDTO>();
public void setMeetingID(int meetingID){
this.meetingID=meetingID;
}
public int getMeetingID(){
return this.meetingID;
}
public void setMeetingName(String meetingName){
this.meetingName=meetingName;
}
public String getMeetingName(){
return this.meetingName;
}
public void addMeetingMember(UserDTO user){
members.add(user);
}
public void removeMeetingMember(UserDTO user){
members.remove(user);
}
public List<UserDTO> getMeetingMember(){
return this.members;
}
}
在调用类中
private int meetingID;
private String meetingName;
private List<UserDTO> members=new ArrayList<UserDTO>();
public void setMeetingID(int meetingID){
this.meetingID=meetingID;
}
public int getMeetingID(){
return this.meetingID;
}
public void setMeetingName(String meetingName){
this.meetingName=meetingName;
}
public String getMeetingName(){
return this.meetingName;
}
public void addMeetingMember(UserDTO user){
members.add(user);
}
public void removeMeetingMember(UserDTO user){
members.remove(user);
}
public List<UserDTO> getMeetingMember(){
return this.members;
}
}
在调用类中
有如是用法
public Meeting[] meeting=new Meeting[7];
meeting[0].setMeetingName("test1");
meeting[1].setMeetingName("test2");
.......
肯定会被NPE,因为meeting是一组变量名称,没有实际的内存地址,只有meeting有实际的内存地址,
这和 public String[] strArr=new String[7];
strArr[0]="test1";
strArr[1]="test2";
.......
这样用法肯定正确,因为String是系统识别的类型,所以可以直接分配内存。
玩了一个小时,就不知道是什么原因,,最后因为是这东西。。。无语了!!!!