Question

I have a problem with RMS, what I need is to delete an record and move the records after level up, is there any chance to do it? I've tried to avoid this, but all in all I end up with this :(


Is there any way to convert this:

public void profilRmsPopulator(Form fr, ChoiceGroup hg) throws RecordStoreNotOpenException, RecordStoreException{
     int spacePos=0;

       for (int i =1; i<=rs.getNumRecords();i++){

       System.out.println("for loop\n");

  spacePos=RmsToStringDumper(i).indexOf(" ");
       System.out.println("spacePos: \n" +spacePos);

        hg.append(RmsToStringDumper(i).substring(0, spacePos),null);
           }

       fr.append(hg);

}

into while (recordEnumeration.hasNextElement())? Of course with this string trimming :P


ok, maybe I'll explain the problem I'm suffering now. I've created an app on mobile which as far as now is creating a user profile and writing it in a RMS, and it's working just fine. The algorithm works like this: user is asked for name of profile and some other details, when he/she is done, Data is being saved. The schema of the record looks like this: Name_of_profile, model, brand etc. Than the program trims the records to get the name_of_profile and puts it in the choiceGroup. And it also worsk like a charm, but the real problem is with deleting, I can delete first or second record, but when I put new one [ new profile ] I'm receiving error like this:

javax.microedition.rms.InvalidRecordIDException: error finding record

Was it helpful?

Solution

I presume you mean you need to 'renumber' the record ids so that the gap created by the deletion does not exist, and you have a neat series of ids ranging from 1 up to n, the number of records.

You could do that, but it would be expensive - there is no 'update' for records, only add/insert/delete operations. So you would need to iterate over all the records, reading them, deleting them and writing them back with the modified id. Applying the changes in the right order might be tricky too.

Why do you need to eliminate the gaps? You can iterate over the complete set, 'skipping' gaps using the RecordEnumeration returned by the RecordStore enumerateRecords method. Or, you could get an array of the current set of ids using the getRecordIDs method. In either case you can iterate without seeing gaps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top