我有項目要做,我必須添加人員到數據庫,然後刪除他們,但是當我嘗試從數組列表中刪除一個人它的作品,但是當我嘗試添加更多在我得到索引超出界限例外?刪除不能在arraylist?
public void removePerson(List<Person> CrecheList) {
if (CrecheList.isEmpty()) {
JOptionPane.showMessageDialog(null, "You need a Child or parent in the database", "Error", JOptionPane.INFORMATION_MESSAGE);
} else {
String pickid = JOptionPane.showInputDialog(null, "Please Enter an id");
int id = Integer.parseInt(pickid);
Iterator<Person> i = CrecheList.iterator();
while (i.hasNext()) {
Person p = i.next();
if (p.getID() == id) {
i.remove();
} else {
JOptionPane.showMessageDialog(null, "There is no such person in the database", "Child name", JOptionPane.INFORMATION_MESSAGE);
}
}
}
}
當我刪除並嘗試添加更多的arrylist我索引超出界限?
請向我們展示添加部分。 – NickLH
這是一些瘋狂的縮進。 –
迭代器不保證支持.remove()。它是否拋出了「NotImplementedException」? –