我在我的j2me應用程序中使用rms概念。如何在j2me midlet中刪除rms後讀取記錄?
成功添加到rms的第一條記錄,然後讀取記錄也很好,但是當我要在同一時間添加另一條記錄時,它不會添加到我的列表中,它會成功添加到rms中,但不會刷新時間。
如果我退出應用程序一次然後運行記錄讀取良好的應用程序,所有記錄顯示。如何刷新列表並獲取所有記錄?
這是我記錄添加源:
public void AddCustomer(String str) throws RecordStoreNotOpenException
{
byte[] rec=str.getBytes();
try
{
rs19 = RecordStore.openRecordStore(ADDREMOVE_CUSTOMER, true);
rs19.addRecord(rec, 0, rec.length);
System.out.println("REcord added successfully");
v.addElement(str);
}
catch (Exception e)
{
}
}
這是讀取記錄來源:
public ChoiceGroup getChoiceGroup10() {
if (choiceGroup10 == null) {
choiceGroup10 = new ChoiceGroup("Select Customer", Choice.POPUP);
choiceGroup10.append("none", null);
try
{
rs19.openRecordStore(ADDREMOVE_CUSTOMER, true);
String value="";
String comma=",";
Vector v1=new Vector();
StringBuffer enumList=new StringBuffer();
recEnum = rs19.enumerateRecords(null, null, false);
while(recEnum.hasNextElement())
{
byte[] data = recEnum.nextRecord();
enumList.append(new String(data));
enumList.append(",");
}
records=new String(enumList);
int index=records.indexOf(comma);
while(index>=0)
{
v1.addElement(records.substring(0,index));
records = records.substring(index+comma.length());
index = records.indexOf(comma);
}
v1.addElement(records);
if(v1.size()>0)
{
for(int i=0; i<v1.size(); i++)
{
value= (String)v1.elementAt(i);
choiceGroup10.append(value, null);
}
}
}
catch(InvalidRecordIDException ie)
{
ie.printStackTrace();
}
catch(RecordStoreException re)
{
re.printStackTrace();
}
catch(NullPointerException ne)
{
System.out.println(ne);
}
finally
{
try {
rs19.closeRecordStore();
} catch (RecordStoreException ex) {
ex.printStackTrace();
}
}
}
return choiceGroup10;
}
我也試過你的建議,但沒有得到。 – cheliyan 2012-07-21 09:34:51