J2ME RecordStore更新问题,删除操作

时间:2011-08-13 13:50:54

标签: java-me recordstore

我创建一个List,显示来自RecordStore的数据。我尝试更新记录并重新显示列表(重新打开相同的RecordStore),但更新的项目不会更改(仍包含旧数据)。
我还试图删除一个项目,删除的项目仍然显示在列表中 我使用带有Java ME SDK 3.0的NetBeans 7.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;
    }

1 个答案:

答案 0 :(得分:0)

有趣的是 - 处理记录存储的代码对我来说相当不错。 UI中是否有可能出现一些故障 - 例如使用旧的或错误更新的屏幕对象?

如何调试应用程序?既然你提到了模拟器,那么System.out/println看起来就像是一个自然的选择吗?我在updateClient中设置记录内容并在getClients

中获取后立即输出记录的内容
相关问题