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

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

现在,当用户触发事件时,我想用“已购买”设置我的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); }