Java Micro Edition(J2ME)-使用recordstore枚举更新记录

Java Micro Edition(J2ME)-使用recordstore枚举更新记录,java,java-me,midp,rms,Java,Java Me,Midp,Rms,我有一个记录存储的项目有(名称、数量、所有者、状态) 现在,当用户触发一个事件时,我想用“已购买”来设置RecordStore中所有项目的状态 但是,我正在覆盖下一条记录(使用nextRecordId)。我试过使用nextRecordId-1,但很明显,这超出了第一种方法的范围 希望你能帮忙?你试过了吗 re = shoppingListStore.enumerateRecords(null, null, false); while (re.hasNextElement()) { in

我有一个记录存储的项目有(名称、数量、所有者、状态)

现在,当用户触发一个事件时,我想用“已购买”来设置RecordStore中所有项目的状态

但是,我正在覆盖下一条记录(使用nextRecordId)。我试过使用
nextRecordId-1
,但很明显,这超出了第一种方法的范围

希望你能帮忙?

你试过了吗

re = shoppingListStore.enumerateRecords(null, null, false);

while (re.hasNextElement())
{
    int id = re.nextRecordId();
    // read current values of item
    byte [] itemRecord = shoppingListStore.getRecord(id);
    // deserialise byte array
    newItemObject.fromByteArray(itemRecord);
    // set item status to purchased
    newItemObject.setItemStatus("Purchased");
    // create new bytearray and call newitemobject . tobytearray method to return a byte array of the object (using UTF8 encoded strings~)
    byte[] itemData = newItemObject.toByteArray();

    // update shoppinglist store record with new byte array
    shoppingListStore.setRecord(id, itemData, 0, itemData.length);
}
你试过了吗

re = shoppingListStore.enumerateRecords(null, null, false);

while (re.hasNextElement())
{
    int id = re.nextRecordId();
    // read current values of item
    byte [] itemRecord = shoppingListStore.getRecord(id);
    // deserialise byte array
    newItemObject.fromByteArray(itemRecord);
    // set item status to purchased
    newItemObject.setItemStatus("Purchased");
    // create new bytearray and call newitemobject . tobytearray method to return a byte array of the object (using UTF8 encoded strings~)
    byte[] itemData = newItemObject.toByteArray();

    // update shoppinglist store record with new byte array
    shoppingListStore.setRecord(id, itemData, 0, itemData.length);
}

刚试过上面的代码,如果你输入re.getRecord(id)并执行recordStoreName.getRecord(id),那么它就起作用了:)谢谢(编辑你的代码,我会勾选你的答案)谢谢刚试过上面的代码,如果你输入re.getRecord(id)并执行recordStoreName.getRecord(id),那么它就起作用了:)谢谢(编辑你的代码,我会勾选你的答案)谢谢