private void btnOKActionPerformed(java.awt.event.ActionEvent evt)
{
try
{
if(txtStaffID.getText(0, 2).equals("AD"))
{
for(Admin admin:admincontrolpanel.adminList)
{
if(txtUsername.getText().equals("") || txtPassword.getText().equals("") || txtName.getText().equals("") || txtEmail.getText().equals("") || txtContactNumber.getText().equals("") || txtICNumber.getText().equals(""))
{
JOptionPane.showMessageDialog(null, "Please fill in the blank", "ERROR", JOptionPane.ERROR_MESSAGE);
}
else if(txtUsername.getText() != null && txtPassword.getText() != null && txtName.getText() != null && txtEmail.getText() != null && txtContactNumber.getText() != null && txtICNumber.getText() != null)
{
admin.setId(txtStaffID.getText());
admin.setUsername(txtUsername.getText());
admin.setPassword(txtPassword.getText());
admin.setName(txtName.getText());
admin.setEmail(txtEmail.getText());
admin.setContactNumber(txtContactNumber.getText());
admin.setIcNumber(txtICNumber.getText());
Admin newAdmin = new Admin(admin.getId(),admin.getUsername(),admin.getPassword(),admin.getName(),admin.getEmail(),admin.getContactNumber(),admin.getIcNumber());
admincontrolpanel.adminList.remove(admin);
admincontrolpanel.adminList.add(newAdmin);
}
}
JOptionPane.showMessageDialog(null, "Successfully Added!", "Add Staff", JOptionPane.PLAIN_MESSAGE);
dispose();
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
Inside the text file got these data...
AD001|jeff|jeff|jeff|jeff@gmail.com|123456|123456
AD002|admin|admin|admin|admin@gmail.com|123456|123456
When I press OK button to edi...it shows me this ConcurrentModificationException error....Anyone can help me to take a look of it?? Admin is the class...adminList is the arraylist...
try
{
PrintWriter pw = new PrintWriter("Admin.txt");
for(Admin admin:admincontrolpanel.adminList)
{
pw.println(admin.getId() + "|" + admin.getUsername() + "|" + admin.getPassword() + "|" + admin.getName() + "|" + admin.getEmail() + "|" + admin.getContactNumber() + "|" + admin.getIcNumber());
}
pw.close();
}
catch(Exception e)
{
e.printStackTrace();
}
This is the code i want to write into the text file from arraylist.... then it gave me this kind of data inside the arraylist...can edit it..but deleted the 1st data and add a new data into it
AD002|admin|admin|admin|admin@gmail.com|123456|123456
AD002|admin|admin|admin|admin@gmail.com|999|123456