Reputation: 17
I am working with persistent store and persistent object.I am being able to save values.I am storing each primitive into a vector and then saving the vector.So what happens now,when i start the app and say save three values.Those values are stored in the vector.Than if i start the app,n check for those values,its displaying the saved values properly.Now if i say again save two more values,than total saved value in the vector should be 5.But when i close the app and restart it.It shows only the last two values which i saved,the earlier three saved value is not displaying.Please help me
package com.kcrw.ui;
import java.util.Random;
import net.rim.device.api.system.PersistentObject;
import net.rim.device.api.system.PersistentStore;
import java.util.Vector;
import com.kcrw.model.Song;
import net.rim.device.api.util.Arrays;
import net.rim.device.api.util.Persistable;
public class Persist implements Persistable{
public static PersistentObject abc;
public static PersistentObject abc1;
public static PersistentObject abc2;
public static PersistentObject abc3;
public static String b;
public static String c;
public static String d;
public static String e;
public static Vector vect;
public static Vector xyz=new Vector();
static {
abc = PersistentStore.getPersistentObject(0xb92c8fe20b256b82L);
abc1 = PersistentStore.getPersistentObject(0xa94f6433aaf45909L);
abc2 = PersistentStore.getPersistentObject(0xfbe29f690c998fb1L);
abc3 = PersistentStore.getPersistentObject(0x67a6bd7c03940754L);
}
public static void data(){
synchronized (abc) {
abc.setContents(((Song) MoreInfoSongDetails.shows.elementAt(MoreInfo.listFieldIndex))
.getTitle());
abc.commit();
}
synchronized (abc1) {
abc1.setContents(((Song) MoreInfoSongDetails.shows.elementAt(MoreInfo.listFieldIndex))
.getAirtime());
abc1.commit();
}
synchronized (abc2) {
abc2.setContents(((Song) MoreInfoSongDetails.shows.elementAt(MoreInfo.listFieldIndex))
.getAlbumImage());
abc2.commit();
}
synchronized (abc3) {
System.out.println("vector size is"+xyz);
abc3.setContents(xyz);
abc3.commit();
}
}
public static String getTitle() {
synchronized (abc) {
b= (String)abc.getContents();
//xyz.addElement(b);
return b;
}
}
public static String getTime() {
synchronized (abc1) {
c= (String)abc1.getContents();
//xyz.addElement(c);
return c;
}
}
public static String getImage() {
synchronized (abc2) {
d= (String)abc2.getContents();
//xyz.addElement(d);
return d;
}
}
public static Vector save() {
synchronized (abc3) {
vect= (Vector)abc3.getContents();
int i=vect.size();
for(int b=0;b<i;b++){
System.out.println("element at"+b+"is"+vect.elementAt(b));
}
return vect;
}
}
}
Upvotes: 0
Views: 699
Reputation: 3505
Your code example isn't great, but saving and restoring a vector is quite trivial, as shown here:
http://www.blackberry.com/developers/docs/4.5.0api/net/rim/device/api/system/PersistentStore.html
I incorporated this into a little tutorial on object persistence. There's also a PowerPoint deck here that gives even more details.
Look through those pages and you should be able to find your problem.\
Upvotes: 1