2014-01-26 177 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