Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Yo've encountered one of the pitfalls of using Java serialization is a persistence framework (as opposed to a data format for communication). You persisted your student data, then changed the Student class. Now, when you try and read the persisted data it fails because basically, the two versions of the class do not match up. If you had manually specified a <code>serialVersionUID</code> on the student class the serialization framework would not have choked on reading the data file (not right away anyway).</p> <p>But the root problem is that serialization is not the same as persistence - if you want to save your Student data then you need to select a framework for doing so that is less vulnerable to class file incompatibilities. I would recommend saving as a CSV file to start, and too take a look at a database solution down the line, if the project complexity warrants it.</p> <hr> <p><strong>* EDIT *</strong></p> <p>As a temporary fix you can try renaming the class back to <code>Student</code> and setting the <code>serialVersionUID</code> to what the serialization framework is expecting. This is not a garaunteed fix, it depends on how much the class has changed since it you created the file:</p> <pre><code>public class Student implements Serializable { public static final long serialVersionUID = -3040096452457271695L; // ... } </code></pre> <p>Since its a requirement for your project to use object output stream, I will recommend implementing the <code>Externalizable</code> interface on your <code>Student</code> class, and implementing the methods to read/write it to an object output stream:</p> <pre><code>public class Student implements Serializable, Externalizable { public static final long serialVersionUID = -3040096452457271695L; // ... @Override public void writeExternal(ObjectOutput out) throws IOException { out.writeUTF(getStudentID()); out.writeUTF(getName()); // etc } @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { setStudentID(in.readUTF()); setName(in.readUTF()); // etc } // ... } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload