This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 ...
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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 */

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!