I create a List showing data from a RecordStore. I tried to update a record and the re-display the list (re-open the same RecordStore), but the updated item doesn't change (still contain the old data).
I also tried to delete an item and the deleted item is still displayed in the list.
I run the program using emulator from NetBeans 7.0 with Java ME SDK 3.0
This is the code for updating the record
public void updateClient(Client cl) throws Exception{
RecordStore rs=RecordStore.openRecordStore(String.valueOf(clientsStoreKey), true);
int recNum=rs.getNumRecords();
if (recNum>0){
RecordEnumeration renum=rs.enumerateRecords(null, null,false);
while(renum.hasNextElement()){
int id = renum.nextRecordId();
byte[] buff=rs.getRecord(id);
Client temp=Client.createFrom(buff);
if(temp.clientId.compareTo(cl.clientId)==0){
temp.firstName=cl.firstName;
temp.lastName=cl.lastName;
temp.city=cl.city;
temp.state=cl.state;
temp.company=cl.company;
temp.phone=cl.phone;
ByteArrayOutputStream bos=new ByteArrayOutputStream();
DataOutputStream dos=new DataOutputStream(bos);
temp.writeTo(dos);
byte[] sData=bos.toByteArray();
rs.setRecord(id, sData, 0, sData.length);
dos.close();
bos.close();
break;
}
}
renum.destroy();
}
rs.closeRecordStore();
}
And this is the code to get the records
public Vector getClients()
throws Exception{
RecordStore rs=RecordStore.openRecordStore(String.valueOf(clientsStoreKey), true);
int recNum=rs.getNumRecords();
Vector cls=new Vector();
if (recNum>0){
RecordEnumeration renum=rs.enumerateRecords(null, null,false);
while(renum.hasNextElement()){
byte[] buff=renum.nextRecord();
Client cl=Client.createFrom(buff);
cls.addElement(cl);
}
renum.destroy();
}
rs.closeRecordStore();
return cls;
}
interesting - your code dealing with record store looks rather OK to me. Is there a chance for some glitch in UI - like say using old or incorrectly updated screen object?
How do you debug your application? Since you mention emulator,
System.out/println
looks like a natural choice doesn't it? I'd use it to output content of the record right after setting it inupdateClient
and after getting it ingetClients