A THOUSAND APOLOGIES!!! I JUST COUNTED HOW MANY TIMES I INSERTED RECORDS
EDIT: here's a REAL question.
here's what i no. rebuild is like 'reinitializing' the recordnum. you're using an existing one. renum setting its 3rd parameter to true is a good thing tho it might come at a cost of performance.
{code}
try
{
RecordStore rs = RecordStore.openRecordStore("name", true);
String one = "a", two = "b", three = "c", four = "d", five = "e", six = "f";
/*remove this line*/RecordEnumeration re = rs.enumerateRecords(null, null, true);
byte[] b;
b = one.getBytes();
rs.addRecord(b, 0, b.length);
b = two.getBytes();
rs.addRecord(b, 0, b.length);
b = three.getBytes();
rs.addRecord(b, 0, b.length);
rs.deleteRecord(1);
b = four.getBytes();
rs.addRecord(b, 0, b.length);
b = five.getBytes();
rs.addRecord(b, 0, b.length);
rs.deleteRecord(4);
/*add that line here*/
///*COMMENT1:*/ re.rebuild();
while(re.hasNextElement())
{
System.out.println(re.nextRecordId());
b = re.nextRecord();
System.out.println(b.toString());
}
}
{code}
if i remove enum line and add it where i mentioned in the comment, then i get a result of 2 then nameofbyteinstring then 5 then invalididexception
if i remove the COMMENT1 comment and leave rebuild i get the same result
The current result is 5 then nameofbyteinstring then 2 then invalididexception. so rebuilding is a good thing.
now, can someone please explain to me why im getting 5 after 2 let alone an exception? i thought it didnt jump through 'holes' but it did. but thts wierd. all i deleted were 2 records. wht happened to records 2 3 5 6? why did it jump from 2 to 5?
how do i fix this?
EDIT HERE LOOK HERE
any chance the reason why im getting an invalididexception is because re.nextRecord and .nextRecordID actually move the pointer to the next record and get the information? so what really happened is tht i printed the id of 2, the string representation of 4 and then the id of 5? cuz thts what it looks like. i ran the loop with only one print statement (id) and i got 2 3 5. i tried nextrecord alone and i got 3 strin names of the byte objects.
so this isnt like a while where you keep the pointer where it is and look ahead at the next record to find out if its null.
so there are two slutoins to track this
either have two recordenumerators, one for nextrecord, the other for nextrecordid
OR
whenever the list iof records is created i create a vector or array where i insert the index of each record. everytime i delete the record, i update the vector/array by removing it from the list.
any other third solution? thanks