File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java Micro Edition and the fly likes Doubt in deletion of record in RMS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "Doubt in deletion of record in RMS" Watch "Doubt in deletion of record in RMS" New topic

Doubt in deletion of record in RMS

Chandrasekaran Sathasivam

Joined: Dec 29, 2000
Posts: 11
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 */

I agree. Here's the link:
subject: Doubt in deletion of record in RMS
It's not a secret anymore!