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);
}[/CODE]
Re: problem while deleting a record (i'm new 2 j2me)
[QUOTE=im2amit;907633]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...?[/QUOTE]
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.
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..
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.
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..
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!!
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.
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..
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);
Re: problem while deleting a record (i'm new 2 j2me)
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.