2014-01-26 81 views
0

我想每次使用此代码时从RecordStore中删除一条记录,这意味着第二次用户看到记录时,他不应该看到已删除的记录,但这种情况不会发生。从RecordStore中删除记录

经过测试我的代码创建recordStore上的相同记录。 !

这些是我输入的记录。

_1_Elhadi_ _Sun 1月26日01:00:00 GMT + 03:00 2014

_A_John_ 太阳1月26日01:00:00 GMT + 03:00 2014

_3_Smith_ 太阳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(); 
} 
    }    
+0

@AliPour您能否提供吗? – JavaFan

回答

0

我认为错误是这一行:

String next = new String(e.toString()); 

你看上去转换您的RecordEnumeration对象转换成String对象,并试图找到该字符串记录ID。这不会让你走得很远。

尝试用这条线替换该行,并看看是否有帮助:

String next = new String(recordStore.getRecord(id)); 
+0

感谢您的回复。但不幸的是,它并没有解决我的问题。 – JavaFan