Hey,

I'm trying to store data in a record store then sort it, but I'm getting weird results when I try to add anything to the recordstore object...

I was using a for loop to add records, and I noticed that the recordStore contained way more records than I added. I tried getting rid of the loop and just adding one to see if it was the loop that was doing it and I still had the same issue.

SOMETIMES after adding one record rs.getNumRecords() will return 1. Sometimes it returns some large number (usually 83).

Am I adding records the wrong way? Anyone know what is up?

I initialize the recordstore with:

try{rs = RecordStore.openRecordStore("Strings", true);}
        catch(Exception e){System.out.println("Error in constructor (create rs): " + e.getMessage());

Then in another function I try to add a single record:

String s = "hi";
            dataToAdd = s.getBytes();
            rs.addRecord(dataToAdd, 0, dataToAdd.length);
   
            
            RecordEnumeration re;
            re = rs.enumerateRecords(null, null, false);
               System.out.println("Enumeration says: " + re.numRecords() + " records");
            
            
             System.out.println("Added " +rs.getNumRecords() + " to rs");

both the the recordstore and recordEnumeration both always return the same value (like I said, sometimes 1 sometimes much higher)

Any help would be appreciated!

Figured it out right after I posted.... Netbeans was apparently saving the recordstore after I exited the simulation.

If I change the name of the recordStore every time I run it, it tells me there is only one record in it.

Thanks anyways!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.