0

I serialize all of my class but get exception...anyone can say which one of class properties cause this problem?

1-

    public class UserManage  {
       public ArrayList<User> users=null;

2-

public class User implements java.io.Serializable      {
    private String firstName;
    private ArrayList<Repository> userRepositories=null;

3-

public class Repository implements java.io.Serializable {
    public  String parentPathOfAllRepositories="D:\\TestOfJava";
    private ArrayList<String> contributorsID=null;
    private String ParentDefaultPath=null;
    private HashMap<File,String> LockListFile=null;
    private HashMap<File,String> FileHashlist=null;
    private String VersionHolderFolderPath=null;

    private HashMap<HashMap<File,String>,HashMap<Date,String>> VersionsList=null;

I must say that ArrayList<User> in class UserManage must be serialize to a file

[Update]:Exception Message:java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: Client.User

MEAM
  • 61
  • 8
  • update your exception message also. – Piyush Gupta Dec 17 '15 at 06:58
  • 2
    Show us the exception message. – Louis Wasserman Dec 17 '15 at 06:58
  • @LouisWasserman.In my Last post http://stackoverflow.com/questions/34319544/notserializableexception-wiht-hashmap-serialize?noredirect=1#comment56383736_34319544 you said me to serialize.but i serialize and got this exception again – MEAM Dec 17 '15 at 07:02
  • 1
    I do not see any non-serializable classes in the `User` class, but I would either remove all fields and add them one by one again to see which one is causing the issue or put `transient` in front of all fields and then remove it one by one while executing the serialization after each step. Also, ideally provide a [mcve] so that we can reproduce the issue. – Andreas Fester Dec 17 '15 at 07:13

1 Answers1

0

If your object doesn't implement java.io.Serializable this code throw a NotSerializableException, and the same applies to all its non-static and non-transient data members, and so on recursively until closure. Use specified SerialVersionUID is better, so JVM don't calculate it at runtime. Please also implement the Serializable to UserManage class.

In case of array or collection, all the objects of array or collection must be serializable. If any object is not serialiizable, serialization will be failed.

if you have inner class inside your class,then an inner class always holds an implicit reference to its outer class, you cannot serialize an inner class unless the outer class is also serializable. Actually it's not even recommended to try;

look in to this reference http://docs.oracle.com/javase/7/docs/platform/serialization/spec/serial-arch.html#4539

Zia
  • 1,122
  • 11
  • 24
  • I `implements serializable` but get this error again! :( I think has a problem with inner class! but don't know which one! @Zia – MEAM Dec 17 '15 at 07:15
  • You have inner classes in your code? Then show them - as said, please provide a [mcve], otherwise we can not determine the issue – Andreas Fester Dec 17 '15 at 07:16