nnn
nnn

Reputation: 13

Invalid Class Exception

My app worked, and after I changed my names to English version I got InvalidClassEception. How can I solve it? I found some information about it, but I don't understand how can I solve it. Some help? Here is my code:

public class Serializare {
    //private static final long serialVersionUID = 1L;
    public void serialize(Bank bank, String fileName) {
        try (ObjectOutputStream out = new ObjectOutputStream(
                new FileOutputStream(fileName))) {
            out.writeObject(bank);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    public Bank deserializeW(String fileName){
        Bank bank = null;
        try (ObjectInputStream in = new ObjectInputStream(new FileInputStream(
                fileName))) {
            bank = (Bank) in.readObject();
        } catch (IOException | ClassNotFoundException ex) {
            ex.printStackTrace();

        }
        return bank;
    }
}

public class Bank implements BankProc, Serializable {

    /**
     * 
     */
    //private static final long serialVersionUID = -7029959057180382645L;
    private Hashtable<Integer, Account> bank;

    ...

}

My error was

java.io.InvalidClassException: Bank.Bank; local class incompatible: stream classdesc serialVersionUID = -7029959057180382645, local class serialVersionUID = -2329932680711902869

Upvotes: 1

Views: 1120

Answers (1)

bruno
bruno

Reputation: 2273

You tried to serialize a class with a given serialVersionUID and deserialize it with a different one.

See what is a serialVersionUID.

Upvotes: 1

Related Questions