使用new ArrayList<E>()
初始化List时遇到问题。这是我的班级: -
@ManagedBean(name = "clientBean")
@SessionScoped
public class ClientBean {
public String msg = "", input, pendingMsg = "", user = "";
public GossipClient client;
public boolean inputDisabled = true, sendBtnDisabled = true, startBtnDisabled = false;
String key = null;
public List<ClientBeanDto> dtos;
ClientBeanDto dto;
String style;
public List<OnlineList> onlineList;
OnlineList userInfo;
OnlineList newUser = null;
public void start() throws UnknownHostException, IOException {
client = new GossipClient(this);
if (user != null && user != "" && client.connect()) {
try {
BufferedReader reader = new BufferedReader(new FileReader("D://key.txt"));
key = reader.readLine();
reader.close();
} catch (Exception e) {
e.printStackTrace();
}
client.start();
inputDisabled = sendBtnDisabled = false;
startBtnDisabled = true;
msg = pendingMsg = "";
pendingMsg = user + ", you are connected!";
client.sendNick(key + user);
onlineList = new ArrayList<OnlineList>();
dtos = new ArrayList<ClientBeanDto>();
}
.
.
.
}
问题在于public List<OnlineList> onlineList
。在start()
方法中执行行onlineList = new ArrayList<OnlineList>();
时,在调试模式下,我发现它的值为null,而下一行中的类似对象dtos
被初始化并成功分配了一个id。
我似乎无法找到这种行为的任何原因,我没有得到任何错误/异常。任何智慧都将受到赞赏。
更新:每当点击xhtml(bean支持的)按钮时,list
变为null。我找不到原因。 bean是SessionScoped,另一个列表(dtos
)对象被保留。