开发者

Java Micro Edition (J2ME) - Delete element from Record Store

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 ?


Call recordStore.enumerateRecords(null, null, false)

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜