首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从RecordStore中删除记录

从RecordStore中删除记录
EN

Stack Overflow用户
提问于 2014-01-26 13:09:15
回答 1查看 89关注 0票数 0

每次使用此代码时,我都希望从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

代码语言:javascript
复制
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();
 }
     }            
EN

回答 1

Stack Overflow用户

发布于 2014-01-27 07:11:43

我认为错误在于这一行:

代码语言:javascript
复制
String next = new String(e.toString());

看起来,您正在将RecordEnumeration对象转换为string对象,并试图在该字符串中查找记录id。那不会让你走远的。

试着用这一行替换这一行,看看它是否有用:

代码语言:javascript
复制
String next = new String(recordStore.getRecord(id));
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21363761

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档