删除记录记录库

时间:2011-11-03 00:39:46

标签: java-me midp lcdui rms

所以我有一个列表,当用户选择一个项目并单击删除时,我希望它从记录存储中删除该记录。这是我的代码不起作用:

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();
}

抛出InvalidRecordIDException。我尝试输入一个也从未起作用的手动值。

2 个答案:

答案 0 :(得分:2)

请参阅此示例代码以删除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++;
}

有关详细信息,请查看此文章。

答案 1 :(得分:0)

   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();
        }
    }