Little help here, i'am trying to save objects in a ArrayList but getting weird problems.
Following method saving the ArrayList by serialization
public void saveData(){
try{
ObjectOutputStream saveFile = new ObjectOutputStream(new FileOutputStream("SaveObjects.ser"));
saveFile.writeObject(lstAccount);
saveFile.flush();
saveFile.close();
}catch (IOException e){
}
}
And this method reads the saved file
public ArrayList<Account> readSavedObject(){
ArrayList<Account> lstOfAccount = new ArrayList<Account>();
try{
ObjectInputStream readFile = new ObjectInputStream(new FileInputStream("SaveObjects"));
lstOfAccount = (ArrayList) readFile.readObject();
readFile.close();
}catch (Exception e){
}
return lstOfAccount;
}
i'am, getting a problem in the following method. The ArrayList which being saving contains 1 account Name hs password: passme. but however its not finding that Account for some reason. This is my first time use serialization. so help would be much appreciated.
public void FindAccount() {
ArrayList<Account> tempAccountlst = new ArrayList<Account>();
//reading from file saveObject.ser
tempAccountlst = readSavedObject();
try {
String passW = new String(password.getPassword());
for (Account tempUser : tempAccountlst) {
if (tempUser.getName().equals(user.getText())
&& tempUser.getPassword().equals(passW)) {
adminFrame.setVisible(true);
setVisible(false);
}else{
System.out.println("test");
}
}
} catch (Exception e) {
System.out.println("lssssssss");
}
}
This post has been edited by harmy01: 11 July 2010 - 07:27 PM

New Topic/Question
Reply



MultiQuote







|