• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Doubt in deletion of record in RMS  RSS feed

Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends,
I've got error while retrieving records from RMS, after deleting a record in it. The error message is that InvalidRecordID exception.
My doubt is, after deleting a record in RMS, how can we retrieve records. Say for example, an RMS contains five records. I just delete 3 record. Upto this everying goes fine. But while retrieving remaining records after deletion, now it shows only first two records. Remaining two records are not displayed and it shows the above error message.
I hereby included the source code for the deletion application. Kindly give your idea regarding the same.
Expecting for your response,
Here you have to give input as any data and store them by clicking menu command and select Add option in it. If you select Retrieve command it will show the records in RMS. To delete a record say 3, you just give input as 3 and select Delete option from Menu command. Now it will delete 3rd record successfully.
But, if you try to retrieve remaining records now only first two records will be displayed and while accessing third record you will be getting error.
Here is the code.
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;
public class RSDelete extends MIDlet implements CommandListener
private Command retrieveCommand;
private Command okCommand;
private Command deleteCommand;
private Display display;
private TextBox t = null;
String dbn=new String("Sample");
RecordStore rs=null;
int currpos,maxchar;
public RSDelete()
display = Display.getDisplay(this);
retrieveCommand = new Command("Retrieve", Command.OK, 2);
okCommand = new Command("Add", Command.OK, 2);
deleteCommand = new Command("Delete", Command.OK, 2);
t = new TextBox("Enter your data :", "",256, 0);
public void startApp()
public void pauseApp()
public void destroyApp(boolean unconditional)
public void commandAction(Command c, Displayable s)
if(c == okCommand)
String name = "";
name=new String(t.getString());
byte[] data=name.getBytes();
System.out.println(" Record is updated");
if(c == deleteCommand)
int id = Integer.parseInt(t.getString());
int totalRecords = rs.getNumRecords();
boolean flag = false;
for(int i = 1; i <= totalRecords; i++)
if(i == id)
flag = true;
System.out.println("record :"+id+" is deleted ");
System.out.println("No match found");
} /* end of Add command */
if(c == retrieveCommand)
String result = "";
byte[] data = null;
System.out.println("Rows in the rs are :");
System.out.println("records in rms :"+rs.getNumRecords());
int totalRecords = rs.getNumRecords();
for(int i = 1; i <= totalRecords; i++)
data = rs.getRecord(i);
result = new String(data);
System.out.println(i+": " + result);
}catch(RecordStoreException e)
System.out.println(" Error :"+e);
} /* end of command Action */
} /* end of class */

PI day is 3.14 (march 14th) and is also einstein's birthday. And this is merely a tiny ad:
ScroogeXHTML - small and flexible RTF to HTML converter library
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!