tags:

views:

497

answers:

2

I have this code that I have shortened to the most important bits that I think affect the outcome but basically I have an error regarding the bytes. I'm not sure why because this code works in a different program as I have borrowed the code. This is meant to extract the data from the record store with the retrieve button then update it when a change is made with the update button but I can't get it to run.

Can someone please help or point me towards a helpful update recordstore tutorial?

thanks

private RecordStore rs;

    Update = new Form("Update");
    Update.addCommand(new Command("Home", Command.BACK, 0));       
    cmRetrieve = new Command("Retrieve", Command.SCREEN, 1);
    cmUpdate = new Command("Update", Command.SCREEN, 2);
    tfRecID = new TextField("Record ID:", "", 8, TextField.NUMERIC);
    txtName = new TextField("Name of Event: ", null, 15, TextField.ANY);

    Update.append(tfRecID);
    Update.append(txtName);
    Update.addCommand(cmRetrieve);
    Update.addCommand(cmUpdate);
    Update.setCommandListener(this);


    String str;
    byte bytes[];
    int recID;

else
    if (c.getLabel().equals("Retrieve"))
    {
            recID = Integer.parseInt(tfRecID.getString());
            bytes = rs.getRecord(recID);
            str = new String(bytes);
            int idx = str.indexOf(";");
            txtName.setString(str.substring(0, idx));


    }
    else
    if(c.getLabel().equals("Update"))
    {
            recID = Integer.parseInt(tfRecID.getString());
            str = txtName.getString() + ":";
            bytes = str.getBytes();
            rs.setRecord(recID, bytes, 0, bytes.length);

    }
+1  A: 

http://developers.sun.com/mobility/midp/articles/databaserms/ gives a good tutorial on RMS.

From what I can see without running the code, the end index passed to the setRecord is incorrect. You'll need to change:

rs.setRecord(recID, bytes, 0, bytes.length);

to:

rs.setRecord(recID, bytes, 0, bytes.length-1);
Peter
A: 

i dont thisk this is a problem. rs.setRecord(recID, bytes, 0, bytes.length); last parameter is length of bytes