×

Discussion Board

Page 2 of 2 FirstFirst 12
Results 16 to 26 of 26
  1. #16
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,698

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

    According to the documentation, RecordStore uses an incrementing counter for producing the record ID-s. Based on that you can simply check if the number of records is greater than 10, enumerate the records and delete the one with the lowest ID.
    Something like
    Code:
    while(rs.getNumRecords()>10)
    {
        int delid=rs.getNextRecordID(); // or just Integer.MAX_VALUE
        RecordEnumeration re=rs.enumerateRecords(null,null,false);
        while(re.hasNextElement())
        {
            int id=re.nextRecordId();
            if(id<delid)delid=id;
        }
        re.destroy();
        rs.deleteRecord(delid);
    }

  2. #17
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

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

    Quote Originally Posted by im2amit View Post
    When 11th record is added, do you want to delete the 1st one or you want to stop addition of records after 10 are added...?
    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

  3. #18
    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..

  4. #19
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,698

    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.

  5. #20
    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..

  6. #21
    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!!

  7. #22
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    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

  8. #23
    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..

  9. #24
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

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

    OK, when you get a records from Input form - add it to addrBook, using below code -

    int recid=addrBook.addRecord(records.getBytes());
    if recid>10 {
    int delid=recid-10;
    addrBook.deleteRecord(delid);
    }
    //
    When you add 11th record using above code, 11-10 = 1 = 1st record will be deleted, when you add 12th record - 12-10 =2, 2nd record will be deleted and so on.

    for listing all records now available in the recordstore use - re =addrBook.enumerateRecords(null,null,false);
    thanks,
    ~Amitabh
    (Champion of the Month -Aug'13)
    Follow me on my blog for Innovative Mobile Apps

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

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

    Thank you so much

  11. #26
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,698

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

    While it is nice to spin on the RMS, this IllegalStateException likely comes from UI code. You mentioned forms, check if you happen to append some item multiple times. Perhaps inside a code branch related to removing items from the RMS.

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
  •  
×