Search code examples
java-mermsrecordstore

j2me delete record from recordstore


Problem: unable to use deleteRecord() properly

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

Problem description in detail: For example I add "abc" (recordID is 1) , "def" ( id is 2) and "ghi" ( id is 3). When I delete these records in the order rs.deleteRecord(3),rs.deleteRecord(2),rs.deleteRecord(1) everything works like it is supposed to.

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

I want to be able remove the records in any order.

Thanks in advance


Solution

  • I faced the same problem. But after carefully reading the api class and this method I found a line written in the explanation that "The record is deleted from the record store. The recordId for this record is NOT reused." Hence to update and add a specific data at the same record number is not possible in recordstore! Therefore you either need to use Record enumeration technique or use a class with the required fields you want to store , convert it into ByteArray and then store the ByteArray in a record store. Hope this would help you and others.