Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Works for me, GNU/Linux with gij 4.3.2.</p> <p>Make sure all of your fields in the Node class are serializable as well.</p> <p>This is the code I tried (should be equivalent to yours):</p> <pre><code>import java.io.*; public class TestCase { public static void main(String[] args) { try { if (args.length &gt; 0 &amp;&amp; args[0].equals("read")) { ObjectInputStream ois = new ObjectInputStream( new FileInputStream("File.log") ); Node root = (Node) ois.readObject(); ois.close(); System.out.println("Root value: " + root.getValue()); for(Node n : root.children()) System.out.println("Child: " + n.getValue()); return; } Node root = new Node(null, "First"); root.add( new Node(root, "Second.Child.1"), new Node(root, "Second.Child.2") ); ObjectOutputStream oos = new ObjectOutputStream( new FileOutputStream("File.log") ); oos.writeObject(root); oos.close(); } catch(Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); } } } class Node implements Serializable { private static final long serialVersionUID = 2304728943L; private Node _parent; private Node[] _children; private String _value; public Node(Node parent, String value) { this._parent = parent; this._value = value; this._children = new Node[2]; } public void add(Node child, Node child2) { this._children[0] = child; this._children[1] = child2; } public String getValue() { return this._value; } public Node[] children() { return this._children; } public Node parent() { return this._parent; } } </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