帮助java j2me中的RecordStore Update问题?

时间:2009-03-30 15:27:04

标签: java java-me

我有这个代码,我已经缩短到我认为影响结果的最重要的位,但基本上我有关于字节的错误。我不确定为什么因为这个代码在不同的程序中工作,因为我借用了代码。这是为了使用检索按钮从记录存储中提取数据,然后在使用更新按钮进行更改时更新它,但我无法让它运行。

有人可以帮忙或指点我找一个有用的更新记录库教程吗?

感谢

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);

    }

2 个答案:

答案 0 :(得分:0)

http://developers.sun.com/mobility/midp/articles/databaserms/提供了一个关于RMS的好教程。

从我可以看到的不运行代码,传递给setRecord的结束索引是不正确的。你需要改变:

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

为:

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

答案 1 :(得分:0)

我不认为这是一个问题。 rs.set Record(recID,bytes,0,bytes.length); 最后一个参数是字节长度

相关问题