0
votes

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.

2

2 Answers

2
votes

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.

0
votes
   if (c == c3) {
        try {
            int ind = v1.getSelectedIndex();
            String rerds = (String) vect.elementAt(ind);
            int i = Integer.parseInt(rerds);
            rc.deleteRecord(i);
            Alert al = new Alert("Success", "Successfully Deleted", null, AlertType.ALARM);
            Display.getDisplay(this).setCurrent(al);
            loadata();
        } catch (RecordStoreException ex) {
            ex.printStackTrace();
        }
    }