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