[英]Problem with J2ME RecordStore update, delete operation
I create a List showing data from a RecordStore.我创建了一个显示来自 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).我尝试更新记录并重新显示列表(重新打开相同的 RecordStore),但更新的项目没有改变(仍然包含旧数据)。
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我使用 NetBeans 7.0 和 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? UI 中是否有可能出现一些故障 - 比如使用旧的或错误更新的屏幕 object?
How do you debug your application?你如何调试你的应用程序? Since you mention emulator , System.out/println
looks like a natural choice doesn't it?既然你提到了emulator , System.out/println
看起来像是一个自然的选择,不是吗? I'd use it to output content of the record right after setting it in updateClient
and after getting it in getClients
在updateClient
中设置它并在getClients
中获取它之后,我会立即将它用于记录的 output 内容
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.