我基本上希望我的Midlet能够编辑记录。
我有这段代码
信息添加如下
protected void searchForNameToEdit()
{
Editrecord.deleteAll();
try
{
rs = RecordStore.openRecordStore("Detail", true);
RecordEnumeration re = rs.enumerateRecords(new NameMatcher(EditSearch.getString()), null, false);
while (re.hasNextElement())
{
byte [] recordBuffer = re.nextRecord();
String record = new String(recordBuffer);
int endOfName = record.indexOf(";");
int endOfDesc = record.indexOf(";" , endOfName + 1);
int endOfTown = record.indexOf(";", endOfDesc + 1);
int endOfPlace = record.indexOf(";", endOfTown + 1);
int endOfSDay = record.indexOf("/", endOfPlace +1);
int endOfSMonth = record.indexOf("/",endOfSDay + 1);
int endOfSYear = record.indexOf(";", endOfSMonth + 1);
int endOfEDay = record.indexOf("/", endOfSYear + 1);
int endOfEMonth = record.indexOf("/", endOfEDay + 1);
int endOfEYear = record.indexOf(";", endOfEMonth + 1);
int endOfComment = record.indexOf(";", endOfEYear + 1);
int endOfRating = record.indexOf (";", endOfComment + 1);
int endOfReview = record.indexOf (";", endOfRating + 1);
String Name = record.substring(0, endOfName);
String Desc = record.substring(endOfName + 1, endOfDesc);
String Town = record.substring(endOfDesc + 1, endOfTown);
String Place= record.substring(endOfTown + 1, endOfPlace);
String SDay = record.substring(endOfPlace +1, endOfSDay);
String SMonth = record.substring(endOfSDay + 1, endOfSMonth);
String SYear = record.substring(endOfSMonth + 1, endOfSYear);
String EDay = record.substring(endOfSYear + 1, endOfEDay);
String EMonth = record.substring(endOfEDay + 1, endOfEMonth);
String EYear = record.substring(endOfEMonth + 1, endOfEYear);
String Comment = record.substring(endOfEYear + 1, endOfComment);
String Rating = record.substring(endOfComment + 1, endOfRating);
String Review = record.substring(endOfRating + 1, endOfReview);
EtxtName = new TextField("Name of Event: ", Name, 15, TextField.ANY);
EdescEvent = new TextField("Describe the Event : ", Desc, 250, TextField.ANY);
EtownEvent = new TextField("Name of Town : ", Town, 50, TextField.ANY);
EplaceEvent = new TextField("Name of Place : ", Place, 25, TextField.ANY);
EcommentEvent = new TextField("Any comments : ", Comment, 300, TextField.ANY);
EStartDate = new TextField("Start Date : ", SDay + "/" + SMonth + "/" + SYear +";", 300, TextField.ANY);
EEndDate =new TextField("End Date : ", EDay + "/" + EMonth + "/" + EYear +";", 300, TextField.ANY);
EEventRating = new TextField("Event Rating : ", Rating, 10, TextField.ANY);
EOverallReview = new TextField("Overall Review : ", Review, 300, TextField.ANY);
Editrecord.append(EtxtName);
Editrecord.append(EdescEvent);
Editrecord.append(EtownEvent);
Editrecord.append(EplaceEvent);
Editrecord.append(EStartDate);
// Editrecord.append("Start Date; " + SDay + "/" + SMonth + "/" + SYear);
//Editrecord.append("End Date; " + EDay + "/" + EMonth + "/" + EYear);
Editrecord.append(EEndDate);
Editrecord.append(EcommentEvent);
Editrecord.append(EEventRating);
Editrecord.append(EOverallReview);
}
rs.closeRecordStore();
}
catch(Exception e)
{
mAlertConfirmDetailsSaved.setString("Couldn't read details");
System.err.println("Error accessing database");
}
Display.setCurrent(Editrecord);
}
这是执行更新的方法
protected void PerformUpdate()
{
int id;
strEName = EtxtName.getString();
strEDescEvent = EdescEvent.getString();
strETown = EtownEvent.getString();
strEPlace = EplaceEvent.getString();
strStartDate = EStartDate.getString();
strEndDate = EEndDate.getString();
strECommentE = EcommentEvent.getString();
strERating = EEventRating.getString();
strEReview = EOverallReview.getString();
String detailsToUpdate = strEName + ";" +"\n"+
strEDescEvent + ";" + "\n"+
strETown + ";" + "\n" +
strEPlace + ";"+ "\n" +
strEStartDate + ";" + "\n" +
strEEndDate + ";" + "\n" +
strECommentE + ";"+ "\n" +
strERating + ";"+ "\n" +
strEReview + ";";
if (listOfIDs != null)
{
try {
//RecordStore
rs = RecordStore.openRecordStore("Detail", true);
for (Enumeration e = listOfIDs.elements() ; e.hasMoreElements() ;)
{
id = ((Integer)e.nextElement()).intValue();
byte [] detailsBuffer = detailsToUpdate.getBytes();
rs.setRecord(id,detailsBuffer, 0, detailsBuffer.length);
}
rs.closeRecordStore();
mAlertDeleteDone.setString(" Selected record updated");
}
catch(Exception e)
{
mAlertDeleteDone.setString("Couldn't update record");
System.err.println("Error accessing database");
}
}
else
{
mAlertDeleteDone.setString("No records to update");
}
Display.setCurrent(mAlertDeleteDone, mOpeningForm);
}
我不断得到的是没有记录更新的其他结果,我没有理由?
请帮助或给我一个有用的指导谢谢