我正在使用持久性存储和持久对象。我能够保存值。我将每个基元存储到一个向量中然后保存向量。所以现在发生什么,当我启动应用程序并说保存三个值。这些值存储在向量中。如果我启动应用程序,n检查这些值,它正确显示保存的值。现在,如果我再说一次保存两个值,那么向量中的总保存值应为5。但是当我关闭应用程序并重新启动它时。它只显示我保存的最后两个值,之前的三个保存值没有显示。请帮助我
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;
}
}
}
答案 0 :(得分:1)
您的代码示例不是很好,但保存和恢复矢量非常简单,如下所示:
http://www.blackberry.com/developers/docs/4.5.0api/net/rim/device/api/system/PersistentStore.html
我把它合并到一个关于对象持久性的tutorial上。还有一个PowerPoint套牌here,它提供了更多细节。
浏览这些页面,您应该能够找到问题。\