views:

273

answers:

1

Hi there,

I have a record store which holds a list of shopping items i am currently serialising the data like so

** (inside) ItemClass **            
ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
DataOutputStream dataOutputStream = new DataOutputStream(byteOutputStream);

dataOutputStream.writeUTF(getOwner());
dataOutputStream.writeUTF(getItemName());
dataOutputStream.writeInt(getQuantity());

dataOutputStream.close();

return byteOutputStream.toByteArray();

This byte array is then written to the record store like so (using for loop for each id)

for (int i = 1; i <= shoppingListStore.getNumRecords(); i++)
{
     byte[] itemRecord = shoppingListStore.getRecord(i);
     newItemObject.fromByteArray(itemRecord);
     userShoppingList.append(newItemObject.getItemName() + " " + newItemObject.getQuantity() + " " + newItemObject.getOwner(), null);
}

The problem comes from using the ID to treverse through the record store as this may change from deletion etc and as such i keep geting invalid id being thrown. I know i cannot use For each ItemObj : Recordstore so how do i treverse through the record store without having to worry about ids?

Thanks in advance

Andy

+1  A: 

Call recordStore.enumerateRecords(null, null, false)

Then use RecordEnumeration.hasNextElement() and RecordEnumeration.nextRecord()

QuickRecipesOnSymbianOS
thank you very much :)
Garbit