2009-03-30 4 views
0

나는 결과에 영향을 미칠 것으로 생각되는 가장 중요한 비트로 줄이긴하지만 기본적으로 바이트에 관한 오류가있다. 이유는 모르겠지만이 코드는 다른 프로그램에서 작동하기 때문에 코드를 빌 렸습니다. 이것은 검색 버튼을 사용하여 레코드 저장소에서 데이터를 추출한 다음 업데이트 버튼을 사용하여 변경 한 경우 업데이트하지만 실행하도록 할 수는 없습니다.Java j2me의 RecordStore 업데이트 문제에 대한 도움이 필요하십니까?

도움이되는 업데이트 레코드 튜토리얼을 알려 주거나 도와 줄 수 있습니까?

감사

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

    } 

답변

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

내가이 문제가 thisk니까. rs.setRecord (recID, bytes, 0, bytes.length); 마지막 매개 변수는 바이트 길이입니다.

관련 문제