1

I have a class define as follow

public class EvaluationResult implements java.io.Serializable {
    public String ClassName;
    public boolean FeedbackDirected;
    public double HV;
    public double Spread;
    public double PercentageOfCorrectness;
    public double TimeElapsed;
    public ArrayList<double[]> ParetoFront;


}

Doing this

public static void main(String[] args) throws Exception {
         EvaluationResult ae=new EvaluationResult();
         FileOutputStream fileOut =new FileOutputStream("result.txt");
         ObjectOutputStream out = new ObjectOutputStream(fileOut);
         out.writeObject(fileOut);
         out.close();
         fileOut.close();
     }

gives me java.io.NotSerializableException what is the problem?

william007
  • 17,375
  • 25
  • 118
  • 194

3 Answers3

3

you need to implement Serializable marker interface

 public class EvaluationResult implements Serializable { .... }

You should be writing the object (and not the file stream) :

 out.writeObject(ae);
Eugene
  • 117,005
  • 15
  • 201
  • 306
3

You must implement Serializable in the class definition:

public class EvaluationResult implements Serializable {
    public String ClassName;
    public boolean FeedbackDirected;
    public double HV;
    public double Spread;
    public double PercentageOfCorrectness;
    public double TimeElapsed;
    public ArrayList<double[]> ParetoFront;

}
blackpanther
  • 10,998
  • 11
  • 48
  • 78
1

You must implement the Serializable interface ... this implies implementing the following:

Classes that require special handling during the serialization and deserialization process must implement special methods with these exact signatures:

 private void writeObject(java.io.ObjectOutputStream out) throws IOException
 private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException;
 private void readObjectNoData() throws ObjectStreamException;

This tutorial may be of use

ErstwhileIII
  • 4,829
  • 2
  • 23
  • 37