我创建了一个列表,显示来自RecordStore的数据。我尝试更新一条记录并重新显示列表(重新打开相同的RecordStore),但更新后的项没有变化(仍然包含旧数据)。
我还尝试删除一个项目,但已删除的项目仍显示在列表中。
我使用NetBeans 7.0中的仿真器和Java ME SDK3.0运行该程序
这是用于更新记录的代码
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();
} 这是获取记录的代码
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;
}发布于 2011-08-14 00:52:15
有趣的是,你处理唱片商店的代码在我看来还不错。有没有可能在UI中出现一些小问题,比如使用旧的或不正确更新的screen对象?
您如何调试您的应用程序?既然您提到了仿真器,那么System.out/println看起来是一个很自然的选择,不是吗?在updateClient中设置它和在getClients中获取它之后,我会立即使用它来输出记录的内容
https://stackoverflow.com/questions/7050807
复制相似问题