why cannot update?
Hi, i am doin a program that is suppose to update my customerData.txt. i getText() user input, then call addCustomer() which is in the CustomerDBVer2 class. My problem is that, it throws the
JOptionPane.showMessageDialog(null, error.getMessage(),"Failed to update", ERROR_MESSAGE)
my customerData.txt looks like:
john;lim;jol;male;12;2;1965;123456;ang mo kio;abc;abc
can please tell me what is wrong?
thx
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
publicclass CustNewMenu2extends JPanelimplements ActionListener
{
//some swing code
publicvoid actionPerformed (ActionEvent e)
{
if (e.getSource() == saveButton){
String firstName = firstNameTF.getText();
String lastName = lastNameTF.getText();
String userID = userIDTF.getText();
String gender = (String)genderCB.getSelectedItem();
String birthDate = birthDateTF.getText();
String birthMonth = (String) birthMonthCB.getSelectedItem();
String birthYear = birthYearTF.getText();
String phone = phoneTF.getText();
String address = addressTF.getText();
String password = passwordPF.getText();
String confirmPass = confirmPassPF.getText();
JOptionPane.showMessageDialog(null,"in e.getSource == save","save",
JOptionPane.ERROR_MESSAGE);
try{
CustomerDBVer2 custDB =new CustomerDBVer2();
custDB.addCustomer(firstName, lastName, userID, gender, birthDate, birthMonth, birthYear, phone,
address, password, confirmPass);
}
catch (Exception error){
JOptionPane.showMessageDialog(null, error.getMessage(),"Failed to update",
JOptionPane.ERROR_MESSAGE);
return;
}
}}
}
publicvoid addCustomer(String firstName,String lastName, String userID, String gender,String birthDate, String birthMonth,
String birthYear, String telephone, String address, String password, String confirmPass)
throws Exception
{
String file ="customerData.txt";
customerList.add(new CustomerVer2(firstName, lastName, userID, gender, birthDate,
birthMonth, birthYear, telephone, address, password, confirmPass));
try{
BufferedWriter writer =new BufferedWriter (new FileWriter(file));
PrintWriter outFile =new PrintWriter(writer);
for (int i = 0; i < customerList.size(); i++){
CustomerVer2 f = (CustomerVer2) customerList.get(i);
outFile.println(f);
System.out.println(f);
}
outFile.close();
}
catch (FileNotFoundException e){
Exception error =new Exception(file +" not found");
throw error;
}
catch (IOException e){
Exception error =new Exception("Error reading " + file);
throw error;
}
}

