我有项目要做,我必须添加人员到数据库,然后删除他们,但是当我尝试从数组列表中删除一个人它的作品,但是当我尝试添加更多在我得到索引超出界限例外?删除不能在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”? –