Z
Z
ZmeuSnake2016-03-25 12:44:59
Java
ZmeuSnake, 2016-03-25 12:44:59

Why is the object not serialized?

There is a class

public class LinkedListVector implements Vector, Serializable
{
    private class Node
    {
        double value;
        Node next, prev;
    }
    private Node beg;
    private int size = 0;
    private Node current = beg;
    LinkedListVector(){...}
    private Node getEl(int index) throws VectorIndexOutOfBoundsException{...}
    public double get(int number) throws VectorIndexOutOfBoundsException{...}
    public void get(int number, double value) throws VectorIndexOutOfBoundsException{...}
    void add(double _value) {...}
    void del(int index) throws VectorIndexOutOfBoundsException {...}
    public void print(){...}
    public int getLength(){...}
    public double norma(){...}
}

In maine I try to serialize:
LinkedListVector test = new LinkedListVector();
test.add(1);
test.add(2);
test.add(3);
test.add(4);
test.add(5);
FileOutputStream fos = new FileOutputStream(filePath);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(test);
oos.flush();
oos.close();

As a result, the error:
2f6514e0f363416a8f0121422c356f5b.jpg
There is another class
public class ArrayVector implements Vector, Serializable
{
    private int length;
    private double [] arr;

    //и дальше идут методы
    // ...

and serialization of ArrayVector objects works fine.
Why doesn't serialization of LinkedListVector objects work?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2016-03-25
@ZmeuSnake

Learn to read stack traces. It directly says that the inner class of Node is not Serializable, although it should.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question