我将数据保存到记录存储。如果应用程序正在运行,它可以正常工作,但是当我重新启动应用程序时,记录存储中的数据就会丢失。
这是我的加载命令:
try {
int i=1;
display.setCurrent(list2);
RecordStore RS = RecordStore.openRecordStore("recordStore", true);
RecordEnumeration re= RS.enumerateRecords(null, null, true);
adresaURL ad = new adresaURL();
System.out.println("nacteno");
while(re.hasNextElement()){
byte br[] = RS.getRecord(i);
ad.setPopis(new String(br));
br = RS.getRecord(i+1);
ad.setUrl(new String(br));
System.out.println(ad.getPopis());
System.out.println(ad.getUrl());
i+=2;
adresy.addElement(ad);
list2.append(ad.getPopis(), null);
System.out.println("nacteno2");
}
recordStore.closeRecordStore();
} catch (Exception e) {
}
最佳答案
是的,这行不通。
如果您使用 RecordEnumeration
来迭代 RMS(就像您一样),则必须使用 RecordEnumeration.nextRecord()
来检索记录数据。您正在使用 RecordStore.getRecord()
。
RecordEnumeration.nextRecord()
将您的 RecordEnumeration
增加 1。因为您从未调用过它,所以您的循环:
while (re.hasNextElement()) {
...
}
永远不会结束!
关于Java ME记录存储问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5957349/