Not serializable exception even though all fields are serializable

Viewed 92

I have the following class definition which I want to save in a file, and all its fields are serializable, so why isn't the class serializable?

I've read in other responses that I don't need getters and setters, so I've omitted them from the class definition.

private class MyClass implements Serializable
{
    private static final long serialVersionUID = 314L;

    public HashMap<Long, String> allTags = new HashMap<Long, String>();
    public HashMap<String, String> notes = new HashMap<String, String>();
    public HashMap<String, ArrayList<Long>> tags = 
                                   new HashMap<String, ArrayList<Long>>();
}
2 Answers

Straight forward, the enclosing class needs to be Serializable.

If this is an inner class, make the outer class serializable and serialzie outer class instance

Related