views:

257

answers:

1

Hi ,

I am using persistent stores to store data in a Blackberry application. While I create objects and store it in persistent store in same session data is saved properly. But the data is not recovered from store in next session.

How do I fix this?

My code is as follows:

static TrialStore ts = new TrialStore(); static Vector data= new Vector();

synchronized (store) {

store.setContents(data);

ts = new TrialStore();

ts .setElement(TrialStore.USERNAME, username); ts .setElement(TrialStore.PASSWORD, password);

data.addElement(ts);

store.commit();

}

+4  A: 

You need to use the PersistentStore class to get and store the persistable object, for example:

Vector data = (Vector) PersistentStore.getPersistentObject(KEY).getContents();

Once you have updated the data, you can store it using:

PersistentStore.getPersistentObject(KEY).setContents(data);
PersistentStore.getPersistentObject(KEY).commit();
Marc Novakowski
Thanks Marc, my problem solved with above answer. getContents() was missing on my side before setContents()...my silly mistake. Thanks again
imMobile