首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >J2ME RecordStore更新、删除操作出现问题

J2ME RecordStore更新、删除操作出现问题
EN

Stack Overflow用户
提问于 2011-08-13 21:50:54
回答 1查看 865关注 0票数 1

我创建了一个列表,显示来自RecordStore的数据。我尝试更新一条记录并重新显示列表(重新打开相同的RecordStore),但更新后的项没有变化(仍然包含旧数据)。

我还尝试删除一个项目,但已删除的项目仍显示在列表中。

我使用NetBeans 7.0中的仿真器和Java ME SDK3.0运行该程序

这是用于更新记录的代码

代码语言:javascript
复制
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();       

    }  

这是获取记录的代码

代码语言:javascript
复制
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;
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-08-14 00:52:15

有趣的是,你处理唱片商店的代码在我看来还不错。有没有可能在UI中出现一些小问题,比如使用旧的或不正确更新的screen对象?

您如何调试您的应用程序?既然您提到了仿真器,那么System.out/println看起来是一个很自然的选择,不是吗?在updateClient中设置它和在getClients中获取它之后,我会立即使用它来输出记录的内容

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7050807

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档