Using RecordStore in Java J2ME

Posted by me123 on Stack Overflow See other posts from Stack Overflow or by me123
Published on 2010-03-22T15:52:04Z Indexed on 2010/03/28 12:53 UTC
Read the original article Hit count: 405

Filed under:
|
|

Hi,

I am currently doing some J2ME development. I am having a problem in that a user can add and remove elements to the record store, and if a record gets deleted, then that record is left empty and the others don't move up one. I'm trying to come up with a loop that will check if a record has anything in it (incase it has been deleted) and if it does then I want to add the contents of that record to a list. My code is similar to as follows:

      for (int i = 1; i <= rs.getNumRecords(); i++)
      {
        // Re-allocate if necessary

        if (rs.getRecordSize(i) > recData.length)
          recData = new byte[rs.getRecordSize(i)];
        len = rs.getRecord(i, recData, 0);
        st = new String(recData, 0, len);
        System.out.println("Record #" + i + ": " + new String(recData, 0, len));
        System.out.println("------------------------------");
        if(st != null)
        {
            list.insert(i-1, st, null);
        }

      }

When it gets to rs.getRecordSize(i), I always get a "javax.microedition.rms.InvalidRecordIDException: error finding record". I know this is due to the record being empty but I can't think of a way to get around this problem.

Any help would be much appreciated.

Thanks in advance.

© Stack Overflow or respective owner

Related posts about java-me

Related posts about java