0

I have been struggling with this issue since yesterday evening and have not been able to find any solution to it over the web. I am developing an app using Android Studio and I want to save some instances to a local file (instances of the class Table). I have made sure that Table implements java.io.Serializable, along with all its components, but I somehow get the following error:

W/System.err: java.io.WriteAbortedException: writing aborted; 
java.io.NotSerializableException: com.pewletthackard.waiterfocusapp.struct.Table

Even after declaring most of my fields as transient, with only 2 Integer fields left un-transient, I still manage to get this error message. This is some of my class:

import java.io.Serializable;

public class Table implements Serializable,Comparable<Table> {

private final Integer number;

private Integer peopleCovered;
private transient final AbstractShape shape;
private transient Status status = DefaultStatus.WELCOMED;
private transient Timer timer = new Timer(status);
private transient StatusFlow statusFlow;
...

The rest of the class is just made of constructors and getters/setters. Also, this is not an inner class. Can anyone help me out?

Andrew
  • 11
  • 4
  • 3
    Are these classes "Status","Timer" and others are serializable as well? Because they also should be serializable. – Shivam Feb 08 '18 at 12:52
  • As Shivam told you are making use of non serializable objects as attributes of the object you are trying to serialize. Take a look of this question https://stackoverflow.com/questions/1922897/serializable-and-transient . Transient / volatille are considered in compile time, not in runtime time were the exception occurs. – Francisco Valle Feb 08 '18 at 12:54
  • They are. Status is an interface though, but DefaultStatus is Serializable. But I have marked all those fields as transient in order to debug and, as I said, it is still giving me the same error message. – Andrew Feb 08 '18 at 12:57
  • `public abstract class AbstractShape implements Serializable {`, `public enum DefaultStatus implements Status, Serializable {`, `public class Timer implements Serializable {`, `public class StatusFlow implements Serializable{` ; copied and pasted from my code – Andrew Feb 08 '18 at 13:02
  • @Andrew is `Timer` a custom class or `java.util.Timer`? – Eduardo Herzer Feb 08 '18 at 13:03
  • @EduardoHerzer it's a custom class – Andrew Feb 08 '18 at 13:04
  • All classes have serializable objects? – Eduardo Herzer Feb 08 '18 at 13:07
  • I would do the following: Comment all attributes from `Table` except `Integer peopleCovered` and verify it is working. Then uncomment the next attribute and verify if it is still working. And so on, until you get the error. This way you will know exactly which class has the problem and it might be easier to find a solution – Eduardo Herzer Feb 08 '18 at 13:11
  • @EduardoHerzer just rechecked. yes, they all have. and all the objects inside them as well and so on. – Andrew Feb 08 '18 at 13:11

0 Answers0