Java ME record store problem
I save data to Record store. If the aplication is running it works fine, but when I restart aplication data in record store is lost.
Here is my load command:
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(开发者_StackOverflow社区ad.getUrl());
i+=2;
adresy.addElement(ad);
list2.append(ad.getPopis(), null);
System.out.println("nacteno2");
}
recordStore.closeRecordStore();
} catch (Exception e) {
}
Yeah that won't work.
If you use a RecordEnumeration
to iterate through your RMS (as you are), you must use RecordEnumeration.nextRecord()
to retrieve the record data. You are using RecordStore.getRecord()
.
RecordEnumeration.nextRecord()
advances your RecordEnumeration
on by one. As you never call it, your loop:
while (re.hasNextElement()) {
...
}
will never end!
精彩评论