J2me remove record from recordstore

Problem: failed to use correctly deleteRecord()

Background: I have a simple j2me application where I add various lines to the record store and try to manipulate the contents of the record store. I add notes to one screen and then read them differently. I can move back and forth with these screens

Detailed problem description: For example, I add "abc" (recordID is 1), "def" (id is 2) and "ghi" (id is 3). When I delete these entries in order rs.deleteRecord(3),rs.deleteRecord(2),rs.deleteRecord(1), everything works as intended.

When I try to execute any other order, I get "Msg: javax.microedition.rms.InvalidRecordIDException" Also, when I try to read other records after this deletion, there is no output.

I want to delete entries in any order.

Thanks in advance

+3
source share
2 answers

. api , , " . ". , ! , , , ByteArray ByteArray . , .

+2

RecordStore rs... ...

RecordEnumeration re=null;
try {
  re = rs.enumerateRecords(null, null, true);
} catch (RecordStoreNotOpenException ex) {
  ex.printStackTrace();
}

int rid=0;

try {
  while (re.hasNextElement()) {
    rid=re.nextRecordId();
    try {
      rs.deleteRecord(rid);
    } catch (RecordStoreNotOpenException ex) {
      ex.printStackTrace();
    } catch (InvalidRecordIDException ex) {
      ex.printStackTrace();
    } catch (RecordStoreException ex) {
      ex.printStackTrace();
    }
  }
} catch (InvalidRecordIDException ex) {
  ex.printStackTrace();
}
+4

All Articles