Reputation: 496
I'm trying to use lwuit.io.Storage, it works fine while application is running (I can do crud) but it's data clears after closing the application. I've considered:
I'm storing my "car" objects with a Vector, using:
Car c = new Car("ford", 1918);
Vector v = (Vector) Storage.getInstance().readObject("cars");
if (v == null) {
v = new Vector();
}
v.addElement(c);
Storage.getInstance().writeObject("cars", v);
Vector test = (Vector) Storage.getInstance().readObject("cars");
if (test.lastElement() instanceof Car){
Car c1 = (Car) test.lastElement();
System.err.println(c1);
}
avoiding call "Storage.getInstance().clearStorage();" anywhere in the code!
"Storage.getInstance().listEntries();" returns one element array containing "cars" String (even after restarting application).
this is my simple "car" class.
any idea what I'm missing / doing wrong here?
thanks in advance
Upvotes: 2
Views: 347
Reputation: 496
I got it, that was a stupid mistake,
The problem was in implementing Externalizable inteface, I was calling "Util.writeUTF(name);" in externalize() method, and trying to read it with "stream.readUTF()" in internalize method.
simply replaced "Util.writeUTF(name)" with "stream.writeUTF(name)".
and it worked out.
Upvotes: 2