So I have a list and when the user selects an item and clicks delete I want it to delete the record from the record store. Here is the code I have which doesn't work:
i = list.getSelectedIndex();
RecordEnumeration re = null;
try {
re = rs.enumerateRecords(null, null, true);
}
catch (RecordStoreException rse )
{
}
try {
rs.deleteRecord(i);
} catch (RecordStoreNotOpenException ex) {
ex.printStackTrace();
} catch (InvalidRecordIDException ex) {
ex.printStackTrace();
} catch (RecordStoreException ex) {
ex.printStackTrace();
}
It throws an InvalidRecordIDException
. I tried entering a manual value which also never worked.
See this sample code for deleting the record's in the RecordStore
.
int i = 0;
String listValue = list.getString(list.getSelectedIndex());
while(e.hasNextElement()) {
String value = new String(e.nextRecord());
if(value.equals(listValue)) {
s.deleteRecord(i);
s.closeRecordStore();
}
i++;
}
For more info, look on this article's.