×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    2

    RMS invalid ID Exception

    Hi guys,
    I'm Italian j2me developer (sorry for my english) and I have a problem with RMS.

    I've write a simple midlet who can send and receive a simple SMS message.
    All the SMS received are writing on RMS with this simple classification:

    ---------------------------------
    text: m1

    sender: sms://+5550002

    date: Mon Jun 18 21:19:13 UTC 2007

    ID: 1

    ---------------------------------
    text: m2

    sender: sms://+5550002

    date: Mon Jun 18 21:19:20 UTC 2007

    ID: 2

    ---------------------------------
    text: m3

    sender: sms://+5550002

    date: Mon Jun 18 21:19:39 UTC 2007

    ID: 3

    Well, my big probem is when I try to delete one of this record from RecordStore.

    I try to do:

    Record ID1-->not delete-->ID1
    Record ID2-->delete-->deleted from RecordStore
    Record ID3-->not delete-->new ID = 2
    Record ID4-->not delete-->new ID = 3
    .
    ..
    ...
    ....

    When I try to re-write record with new ID the InvalidRecordIDException compare to screen.

    What should I do??

    please, I need help, is my last university examination and resolved this problem I graduate myself!!!
    Thanks a lot guys!!
    Good night at all (only for european people ;-))

  2. #2
    Regular Contributor
    Join Date
    Aug 2006
    Posts
    307

    Re: RMS invalid ID Exception

    When record is deleted from the record store, the record ID for that record is NOT reused, so all the other records' IDs will remain the same.

    In order to reallocate records you can use the method enumerateRecords(RecordFilter filter, RecordComparator comparator, boolean keepUpdated).

    If you'll specify the following method call: enumerateRecords(null, null, true), then the enumeration returned simply will have a set of all the records currently stored in RMS.

    The returned enumeration's method hasNextElement() will get you true while there are records in RMS.

    And the following code will give you the record's data back, using the enumeration:

    byte[] data = recordStore.getRecord( enumeration.nextRecordId() );
    Last edited by axs; 2007-06-19 at 11:46.

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    2

    Re: RMS invalid ID Exception

    Thanks AXS for your quickly reply!!
    But I try to clear what I have to do:

    When SMS come to mobile phone A this will be a record written on RMS like this:


    try{
    ByteArrayOutputStream strmbyte = new ByteArrayOutputStream();
    DataOutputStream strmdatatype = new DataOutputStream(strmbyte);
    byte[] record;

    strmdatatype.writeUTF(t);
    strmdatatype.writeUTF(m);
    strmdatatype.writeUTF(d);
    strmdatatype.writeInt(ID);


    record = strmbyte.toByteArray();
    rs.addRecord(record,0, record.length);
    strmbyte.reset();
    strmbyte.close();
    strmdatatype.close();

    }
    catch (Exception e1){
    db(e1.toString()+" writestream");

    }

    }


    The code for deleting record i is:

    byte[] recData = new byte[5000];
    ByteArrayInputStream strmbyte = new ByteArrayInputStream(recData);
    DataInputStream strmdatatype = new DataInputStream(strmbyte);


    for(int i = 1; i <= rs.getNumRecords(); i++)
    {
    rs.getRecord(i, recData, 0);

    if(i==tmp){//tmp is the selected record

    rs.deleteRecord(i);
    }

    But I don't understand where I have to use RecordEnumeration!!
    Is this a method for make an order on RecordStore only when I try to read some records or it is useful also to write a new RecordStore ID's order?

    Thanks thousands guys!!

  4. #4
    Super Contributor
    Join Date
    Feb 2006
    Posts
    689

    Re: RMS invalid ID Exception

    Hi,
    Record enumeration is another way to access records in the data base.RecordEnumeration lets you traverse through a set of records. Unlike Enumeration, however, RecordEnumeration allows for bidirectional traversal of that set -- you can go backwards through the set of records as well as forwards. The set of records to traverse is defined by the enumerateRecords method.
    RecordStore rs = .....; // an open record store
    RecordEnumeration enum = null;

    try {
    enum = rs.enumerateRecords( null, null, false );
    while( enum.hasMoreElements() ){
    int id = enum.getNextRecordId();
    // do something here with the record
    }
    }
    catch( RecordStoreException e ){
    }
    finally {
    enum.destroy();
    }

    Thanks
    Soku

  5. #5
    Regular Contributor
    Join Date
    Aug 2006
    Posts
    307

    Re: RMS invalid ID Exception

    OK, so you're storing the SMS Ids in the RMS. And want to redefine SMS Ids after one SMS was deleted, right?

    If it is so, then your record adding code is just OK. The problem is in record deleting code, since the RMS is not re-organizing records after one was deleted (and not redefining the RMS ids that records have).

    If, for example, you have currently 3 records in RMS, their IDs could be 1, 10 and 11 (I'm not meaning the SMS Ids that you're storing, but the Record IDs which RMS uses), since, for example, previously deleted records had IDs from 2 to 9.

    So, the for loop for (int i = 1; i <= rs.getNumRecords(); i++) will, of course, run 3 times in such case, but the codeline rs.getRecord(i, recData, 0); will throw InvalidRecordIDException, just because there are no records with ID 2 and 3.

    As you remember, after you deleted an RMS record, you cannot use its ID anymore. That's why the RecordEnumeration exists. Your SMS deleting code would look like this (just to add 2 more cents in what soku123 said):

    Code:
    RecordStore rs = .....; // an open record store
    RecordEnumeration enum = null;
    
    try {
        enum = rs.enumerateRecords( null, null, false );
        while( enum.hasMoreElements() ){
            int rmsID = enum.getNextRecordId();
            // now here your code
            // extract the SMS ID you've stored in this record...
            // compare extracted SMS Id with one you want to delete
            if (extractedSMSId == tmp) {
                //delete the record, containing SMS with the matching ID
                 rs.deleteRecord(rmsID); // note that here we use the record ID
            }
        }
    }
    catch( RecordStoreException e ){
    }
    
    finally {
        enum.destroy();
    }
    Last edited by axs; 2007-06-21 at 07:28.

  6. #6
    Super Contributor
    Join Date
    Feb 2006
    Posts
    689

    Re: RMS invalid ID Exception

    Hi,
    I suppose the problem is solved.....
    thanks
    Soku

Similar Threads

  1. exception :Invalid Locator, need help
    By bybash in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2007-03-13, 01:36
  2. VS.Net 2003 Carbide 2.01 and epoc32.exe
    By ValentinK in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 2
    Last Post: 2007-01-12, 12:31
  3. RMS madness!!!!
    By dzaga in forum Mobile Java General
    Replies: 4
    Last Post: 2002-12-12, 08:57
  4. can not successfully link any sample using .NET
    By lobotomat in forum Symbian Tools & SDKs
    Replies: 2
    Last Post: 2002-08-20, 00:29
  5. 3510i rms RecordStoreFull exception
    By boinged in forum Mobile Java General
    Replies: 0
    Last Post: 1970-01-01, 02:00

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×