gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 00:51:58 25 4
gpt4 key购买 nike

我有一个项目记录存储,其中包含(名称、数量、所有者、状态)

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

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

while (re.hasNextElement())
{
// read current values of item
byte [] itemRecord = re.nextRecord();
// 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 objects
// (using UTF8 encoded strings~)
byte[] itemData = newItemObject.toByteArray();

// add new byte array to shoppinglist store

shoppingListStore.setRecord(re.nextRecordId(), itemData, 0, itemData.length);
}

但是我正在覆盖下一条记录(使用 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);
}

关于Java Micro Edition (J2ME) - 使用记录存储枚举更新记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2632788/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com