OK, so you're storing the SMS Ids in the RMS. And want to redefine SMS Ids after one SMS was deleted, right?
If it is so, then your record adding code is just OK. The problem is in record deleting code, since the RMS is not re-organizing records after one was deleted (and not redefining the RMS ids that records have).
If, for example, you have currently 3 records in RMS, their IDs could be 1, 10 and 11 (I'm not meaning the SMS Ids that you're storing, but the Record IDs which RMS uses), since, for example, previously deleted records had IDs from 2 to 9.
So, the for loop for (int i = 1; i <= rs.getNumRecords(); i++) will, of course, run 3 times in such case, but the codeline rs.getRecord(i, recData, 0); will throw InvalidRecordIDException, just because there are no records with ID 2 and 3.
As you remember, after you deleted an RMS record, you cannot use its ID anymore. That's why the RecordEnumeration exists. Your SMS deleting code would look like this (just to add 2 more cents in what soku123 said):
Code:
RecordStore rs = .....; // an open record store
RecordEnumeration enum = null;
try {
enum = rs.enumerateRecords( null, null, false );
while( enum.hasMoreElements() ){
int rmsID = enum.getNextRecordId();
// now here your code
// extract the SMS ID you've stored in this record...
// compare extracted SMS Id with one you want to delete
if (extractedSMSId == tmp) {
//delete the record, containing SMS with the matching ID
rs.deleteRecord(rmsID); // note that here we use the record ID
}
}
}
catch( RecordStoreException e ){
}
finally {
enum.destroy();
}