I have project to do and i have to add people to the database and then remove them but when i try to remove a person from the arraylist it works but when i try to add more in i get index out of bounds exception?
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);
}
}
}
}
and when i remove and try to add more into the arrylist i get index out of bounds?