0
即時嘗試放置在我的Arraylist對象與ArrayList對象,但它不工作在這裏是我的代碼。 我得到的錯誤錯誤:空 顯示java.lang.NullPointerException:我LINEArrayList <Object <ArrayList <Object> >>
mi.get(i).comments.add(new komments());
它應該工作,因爲我= 0和mi.get(我)應該存在
ArrayList<dateiles> mi = new ArrayList<dateiles>();
try {
st = con.createStatement();
rs = st.executeQuery("SELECT * FROM BE");
int i = 0;
while (rs.next()) {
mi.add(new dateiles());
mi.get(i).be = rs.getString("BEBE");
mi.get(i).name = rs.getString("BEBENAME");
mi.get(i).besid = rs.getInt("BEID");
/**
*
* kommentsquery
*
*/
st2 = con.createStatement();
rs2 = st2.executeQuery("SELECT * FROM COMMENTS WHERE BEID='" + mi.get(i).besid + "' ");
int i2 = 0;
while (rs2.next()) {
mi.get(i).comments.add(new komments());
mi.get(i).comments.get(i2).name = rs2.getString("ONAME");
mi.get(i).comments.get(i2).comment = rs2.getString("COMMENT");
i2++;
}
i++;
}
您是否初始化了'comments'? –
哇謝謝我做了拼寫錯誤! – user3110458
'ArrayList