我在我的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