每次使用此代码时,我都希望从RecordStore中删除一条记录,这意味着当用户第二次看到不应该看到已删除的记录的记录时,这种情况不会发生。
在测试了我的代码之后,在recordStore上创建了相同的记录。!!!
这些是我输入的记录。
_1_Elhadi__Sun 1月26日01:00:00 GMT+03:00 2014
_A_John_Sun 1月26日01:00:00 GMT+03:00 2014
_3_Smith_Sun 1月26日01:00:00 GMT+03:00 2014
public void deleteRecStore(String recID) {
try
{
recordStore.openRecordStore("recordStore", true) ;
}
catch(Exception ex)
{
ex.printStackTrace();
}
try
{
RecordEnumeration e = recordStore.enumerateRecords(null,null,false);
int found = -1;
while (e.hasNextElement())
{
int id = e.nextRecordId();
String next = new String(e.toString());
int fee = next.indexOf("_", 1);
**// These statements don't print anything**
System.out.print("next.indexOf" +next.indexOf("_", 1));
System.out.println( "next.substring(1, fee)"+"\t" +next.substring(fee, 1));
System.out.println("recID"+"\t"+recID);
if (next.substring(1, fee).equals(recID))
{
found = id ;
}
}
if (found == -1)
{
System.out.println("not found!");
}
else
{
recordStore.deleteRecord(found);
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
} 发布于 2014-01-27 07:11:43
我认为错误在于这一行:
String next = new String(e.toString());看起来,您正在将RecordEnumeration对象转换为string对象,并试图在该字符串中查找记录id。那不会让你走远的。
试着用这一行替换这一行,看看它是否有用:
String next = new String(recordStore.getRecord(id));https://stackoverflow.com/questions/21363761
复制相似问题