Java Micro Edition (J2ME) - Update Record using recordstore enumeration

Posted by Garbit on Stack Overflow See other posts from Stack Overflow or by Garbit
Published on 2010-04-13T20:01:09Z Indexed on 2010/04/13 20:03 UTC
Read the original article Hit count: 248

Filed under:
|
|

Hi there,

I have a record store of items which have (name, quantity, owner, status)

Now when the user triggers an event i want to set the status of all items in my recordstore with "purchased"

        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 object (using UTF8 encoded strings~)
            byte[] itemData = newItemObject.toByteArray();

            // add new byte array to shoppinglist store

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

However I am overwriting the next record (using the nextRecordId), i've tried using nextRecordId - 1 but obviously this is out of bounds on the first one

Hope you can help,

Many thanks,

andy

© Stack Overflow or respective owner

Related posts about j2me

Related posts about java