×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 26

Hybrid View

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    28

    Question problem while deleting a record (i'm new 2 j2me)

    hi,

    i've an application which stores sms in its inbox..actually it does add the record properly but i'm not able to delete a record ..actually i'm NOT UNDERSTANDING hw 2 get the record id for any specific record TO DELETE IT ..is there any specific method to get the record id for a particular record ??
    and is there any particular process to be followed while deleting a record ..

    hope i get a reply soon

    reagrds,
    dino

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: problem while deleting a record (i'm new 2 j2me)

    What problem do you get when deleting?

    You cannot control record IDs. First record you add is "1". Second is "2" and so on. If you delete a record, that ID disappears, and will not be used again. So, if you delete record ID "3", your records will be 1, 2, 4, 5 (no more "3"). Next you add will be "6" (it will not use "3" again).

    When working with RecordStores, avoid keeping the recordstore open. Open it, use it, close it.

    PHP Code:
    public void doRecordStoreWork() throws RecordStoreException 
        
    RecordStore rs RecordStore.openRecordStore(RECORD_STORE_NAMEtrue); 
        try { 
            
    // add, update or delete records 
        
    finally 
            
    rs.closeRecordStore(); 
        } 

    The close() is in a finally{}, so that the record store is closed no matter what happens. If you do not close the record store properly, you may lose data.

    getNumRecords() tells you the number of records in the store. getNextRecordID() tells you the ID that will be given to the next record you add. These methods can return completely different values. When you delete a record, NumRecords goes down by one. NextRecordID does not change.

    You can see if a record ID is valid, by calling getRecord(), and catching the InvalidRecordIDException. This is a clumsy technique, but it is reliable.

    You can also use the enumerateRecords() method, to scan through records without having to know the IDs.

    However:

    I recommend against updating and deleting records in recordstores. Some devices can corrupt the recordstore if there are may set/add/delete Record()s.

    One technique is to read all the data, delete the recordstore, and create it again with the correct data.

    Cheers,
    Graham.

  3. #3
    Regular Contributor
    Join Date
    Jul 2008
    Location
    Faridabad(Delhi NCR)
    Posts
    343

    Re: problem while deleting a record (i'm new 2 j2me)

    Hey buddy If u directly delete record from Rms ..it wil always give problem...i did too much R&D on Rms...So Best Way Is that...firstly Open record Store
    and get All Data From Record Store and put it in ...Some VEctor...and delete ur database

    Then Delete the record which u wana delete from vector....
    and then Create New RecordStore with same name u created before and put all the vector data in ur recordstore
    this is the best example for deleting database..............

    Hope this wil work......
    Anshu Chauhan
    J2me Developer

  4. #4
    Nokia Developer Champion
    Join Date
    Sep 2008
    Location
    Noida, U.P.
    Posts
    1,330

    Thumbs up Re: problem while deleting a record (i'm new 2 j2me)

    hi dino,
    please check the following thread..

    http://discussion.forum.nokia.com/fo...d.php?t=160112

    there is lots of discussion regarding deletion of record from RMS..and still continues.

    thanks,
    jitu_goldie..
    thanks,
    jitu_goldie..

    KEEP TRYING..

  5. #5
    Registered User
    Join Date
    Jan 2009
    Posts
    28

    Re: problem while deleting a record (i'm new 2 j2me)

    hey guys ,

    thnx for replying ..i'll try them out ...

    regards,
    dino

  6. #6
    Registered User
    Join Date
    Jul 2012
    Location
    South America
    Posts
    43

    Re: problem while deleting a record (i'm new 2 j2me)

    it is working but theres a error something like this

    ERROR!
    Error while building name list:java.lang.illegalStateException

    what is the meaning of that sir.
    when the data reaches the maximum record it says that

    ERROR!
    Error while building name list:java.lang.illegalStateException

    so what is the problem sir ?

    thanks in regard..

  7. #7
    Registered User
    Join Date
    Jul 2012
    Location
    South America
    Posts
    43

    Re: problem while deleting a record (i'm new 2 j2me)

    Thank you mr.wizard_hu_

    my next problem is i have code after your given codes


    }

    }

    }
    } catch (Exception e) {
    displayAlert(ERROR, "Error while building name list:"+e, null);
    return null;
    }
    display.setCurrent(nameScr);

    } else {
    displayAlert(INFO, "No data found", null);
    }

    return nameScr;
    }


    then after i inserted records your given codes is good .. my problem when the form or the rms gets the maximum number of records
    the error appeared something like this..


    ERROR!
    Error while building name list:java.lang.illegalStateException

    but when i open the data form again i see again the data but when i go to registration form again and insert new data and save it..

    then when i check the data in data form ive got again that error


    ERROR!
    Error while building name list:java.lang.illegalStateException

    how can i encouter with that..

    i want to remove that error.. and delete it without any confirmation..





    Thanks in Regard!
    God Bless..

  8. #8
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,568

    Re: problem while deleting a record (i'm new 2 j2me)

    The unfortunate detail is that I do not actually code for Java ME, so I do not know what may happen exactly.
    A good idea would be checking which line causes the exception, it is not necessarily coming from RMS. It should be possible to do with the emulator which is easier to debug with. Checking the documentation shows that RecordStore itself is not expected to throw such thing, and RecordEnumeration throws IllegalStateException if you attempt to use it after a destroy.

  9. #9
    Registered User
    Join Date
    Jul 2012
    Location
    South America
    Posts
    43

    Re: problem while deleting a record (i'm new 2 j2me)

    Hello good day !!
    can i ask something about on how to delete records in j2me within a week i need to have automated deletion for my program example today is december 3,2012 the i have my record 50 records in my record store then tomorrow is december 4,2012 it is possible to delete old records all records in december 3 2012 automatically and all the records in december 4 ,2012 will remain. how can i do that

    Please help me thanks in regard..
    asap..

    God Bless !!!

  10. #10
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,073

    Re: problem while deleting a record (i'm new 2 j2me)

    You need to create your record structure in such a way, that you can easily parse the date out of the record - then - Open the RecordStore, Read all records 1-by-1, Parse and Check if the date is 3 dec - store the records id in a vector called to_delete. Once you pass thu all the records... then delete all record ids stored in to_delete vector.
    thanks,
    ~Amitabh
    (Champion of the Month -Aug'13)
    Follow me on my blog for Innovative Mobile Apps

  11. #11
    Registered User
    Join Date
    Jul 2012
    Location
    South America
    Posts
    43

    Re: problem while deleting a record (i'm new 2 j2me)

    sir this is my codes:

    while(addrBook.getNumRecords()>10)
    {
    int delid=addrBook.getNextRecordID(); // or just Integer.MAX_VALUE
    re =addrBook.enumerateRecords(null,null,false);
    while(re.hasNextElement())
    {
    int id=re.nextRecordId();
    if(id<delid)delid=id;
    }
    re.destroy();
    addrBook.deleteRecord(delid);

    }
    }

    }
    }
    } catch (Exception e) {
    displayAlert(ERROR, "Error while building name list:"+e, null);
    return null;
    }
    display.setCurrent(nameScr);

    } else {
    displayAlert(INFO, "No data found", null);
    }

    return nameScr;
    }


    sir when i look out again the data form

    the error appear and it says that..

    Error!
    Error while building name list:java.lang.IllegalStateException

    what is that sir wizard_hu

    that's the last problem ..

    thanks in regard !!

    GodbLess!!

  12. #12
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,073

    Re: problem while deleting a record (i'm new 2 j2me)

    Simplify your code -- don't add any more records to recordstore if it already has 10 records....

    You can get the number of records in your record store by - int n = your recordstore.getNumRecords();
    if n=10, do not add -- no need to add and delete the 11th record in that case.... Give a warning message to the user - that 10 records already added move to data form.
    thanks,
    ~Amitabh
    (Champion of the Month -Aug'13)
    Follow me on my blog for Innovative Mobile Apps

  13. #13
    Registered User
    Join Date
    Jul 2012
    Location
    South America
    Posts
    43

    Re: problem while deleting a record (i'm new 2 j2me)

    this is my code

    try {
    re = addrBook.enumerateRecords(null, null, true);
    } catch (RecordStoreNotOpenException ex) {
    ex.printStackTrace();
    }

    int rid=0;


    try {
    while (re.hasNextElement()) {
    rid=re.nextRecordId();
    try {
    addrBook.deleteRecord(rid);
    } catch (RecordStoreNotOpenException ex) {
    ex.printStackTrace();
    } catch (InvalidRecordIDException ex) {
    ex.printStackTrace();
    } catch (RecordStoreException ex) {
    ex.printStackTrace();
    }
    }
    } catch (InvalidRecordIDException ex) {
    ex.printStackTrace();

    }



    it seems like when i save the record from textfield it will show to a list menu
    theres a mainscreen that will list all the data that save in registration ..


    then when i open a menu list i can see the data that i saved but i
    i want to have automatically deletion after 1 week all old records will delete
    and the new one for the day will remain..


    can you please give me some idea or code

    thanksss

  14. #14
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,568

    Re: problem while deleting a record (i'm new 2 j2me)

    If you want to delete records by date, you simply have to extend the records to store a date field too. Then you can provide a RecordFilter picking the 1+ week old entries only.

  15. #15
    Registered User
    Join Date
    Jul 2012
    Location
    South America
    Posts
    43

    Re: problem while deleting a record (i'm new 2 j2me)

    sir im2amit good day !!

    they just need to insert records..
    example the records is 10 the last data will remove and you can insert again a record in registration form.
    from 1-10 the 11th data will be removed and the new one will save in data form all i want is theres a 10 records only but when you add
    for the 11th record the last record will be deleted the number 1 and the number 11 will save ..

    i want a overwrite data...

    its ok sir with that but theres an error

    Error!
    Error while building name list:java.lang.IllegalStateException

    whats that sir..

Similar Threads

  1. problem in a j2me program on Nokia 6630/6680
    By lappard in forum Mobile Java General
    Replies: 1
    Last Post: 2006-06-29, 01:43
  2. Obfuscator problem for J2ME polish
    By rudyanto in forum Mobile Java General
    Replies: 0
    Last Post: 2006-05-29, 14:06
  3. Replies: 2
    Last Post: 2006-05-02, 07:19
  4. J2ME HTTP Post problem
    By gilfr in forum Mobile Java General
    Replies: 2
    Last Post: 2003-06-11, 08:13
  5. OTA deploy problem from applications with record stores
    By mpadberg in forum Mobile Java General
    Replies: 0
    Last Post: 2002-12-10, 13:40

Posting Permissions

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