
Originally Posted by
wizard_hu_
RMS is a mandatory feature, and your successful write operations also suggest that it is there. It may be a good idea to post some code here. Or you can also experiment with ready-made examples, for example this Wiki page,
http://www.developer.nokia.com/Commu...t_System_(RMS) links a few. The SDK-s/WTK-s usually contain related examples too.
It seems that I was wrong - the example source code that you have provided via wiki-links is working fine on my device.
----ReadWriteRMS.java----
Code:
package org.mvsys.rms.test;
/*
* http://www.developer.nokia.com/Community/Wiki/How_to_store_Data_in_RMS
*/
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
public class ReadWriteRMS extends MIDlet implements CommandListener {
private Display display;
private Alert alert;
private Form form;
private Command exit;
private Command write;
private Command read;
private Command delete;
private WrapRMS wrap;
public ReadWriteRMS() {
display = Display.getDisplay(this);
wrap = new WrapRMS();
exit = new Command("Exit", Command.EXIT, 1);
write = new Command("Write", Command.SCREEN, 1);
read = new Command("Read", Command.SCREEN, 2);
delete = new Command("Delete", Command.SCREEN, 3);
form = new Form("Mixed Record");
form.addCommand(exit);
form.addCommand(write);
form.addCommand(read);
form.addCommand(delete);
form.setCommandListener(this);
}
public void startApp() {
display.setCurrent(form);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command command, Displayable displayable) {
// EXIT
if (command == exit) {
destroyApp(true);
notifyDestroyed();
}
// WRITE
else
if (command == write) {
try {
wrap.openRecordStore();
}
catch (Exception e) {
Log.showAlert(display, "" + e);
}
try {
wrap.writeRecords();
}
catch (Exception e) {
Log.showAlert(display, "" + e);
}
try {
wrap.closeRecordStore();
}
catch (Exception e) {
Log.showAlert(display, "" + e);
}
}
// READ
else
if (command == read) {
try {
wrap.openRecordStore();
}
catch (Exception e) {
Log.showAlert(display, "" + e);
}
try {
String read = wrap.readRecords();
Log.showAlert(display, read);
}
catch (Exception e) {
Log.showAlert(display, "" + e);
}
try {
wrap.closeRecordStore();
}
catch (Exception e) {
Log.showAlert(display, "" + e);
}
}
// DELETE
else
if (command == delete) {
try {
wrap.deleteStore();
}
catch (Exception e) {
Log.showAlert(display, "" + e);
}
}
}
}
----WrapRMS.java----
Code:
package org.mvsys.rms.test;
import javax.microedition.rms.RecordStore;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
public class WrapRMS {
private RecordStore recordstore = null;
private final String myStoreName = "myRecordStore";
public WrapRMS() {
}
public void openRecordStore() throws Exception {
try {
recordstore = RecordStore.openRecordStore(myStoreName, true);
}
catch (Exception error) {
throw new Exception("Error Creating: " + error);
}
}
public void closeRecordStore() throws Exception {
try {
recordstore.closeRecordStore();
}
catch (Exception error) {
throw new Exception("Error Closing: " + error);
}
}
public void writeRecords() throws Exception {
try {
byte[] outputRecord;
String outputString[] = {"why_you", "Changed", "my_names", "andAdded", "your", "name"};
int outputInteger[] = {25, 21, 20, 23, 34, 34};
boolean outputBoolean[] = {true, false, true, true, false, true};
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
DataOutputStream outputDataStream = new DataOutputStream(outputStream);
for (int i = 0; i < outputString.length; i++) {
outputDataStream.writeUTF(outputString[i]);
outputDataStream.writeBoolean(outputBoolean[i]);
outputDataStream.writeInt(outputInteger[i]);
outputDataStream.flush();
outputRecord = outputStream.toByteArray();
recordstore.addRecord(outputRecord, 0, outputRecord.length);
}
outputStream.reset();
outputStream.close();
outputDataStream.close();
}
catch (Exception error) {
throw new Exception("Error Writing: " + error);
}
}
public String readRecords() throws Exception {
StringBuffer buffer = new StringBuffer();
try {
byte[] byteInputData = new byte[100];
ByteArrayInputStream inputStream = new ByteArrayInputStream(byteInputData);
DataInputStream inputDataStream = new DataInputStream(inputStream);
int numrec = recordstore.getNumRecords();
buffer.append(" Num rec " + numrec);
buffer.append("\n");
for (int i = 1; i <= numrec; i++) {
recordstore.getRecord(i, byteInputData, 0);
buffer.append(inputDataStream.readUTF());
buffer.append("\n");
buffer.append(inputDataStream.readBoolean());
buffer.append("\n");
buffer.append(inputDataStream.readInt());
buffer.append("\n");
}
inputStream.close();
inputDataStream.close();
}
catch (Exception error) {
throw new Exception("Error Reading: " + error);
}
return "Reading: " + buffer.toString();
}
public void deleteStore() throws Exception {
if (RecordStore.listRecordStores() != null) {
try {
RecordStore.deleteRecordStore(myStoreName);
}
catch (Exception error) {
throw new Exception("Error Removing: " + error);
}
}
}
}
----Log.java----
Code:
package org.mvsys.rms.test;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Display;
public class Log {
public static void showAlert(Display d, String body) {
Alert alert = new Alert("Log", body, null, AlertType.WARNING);
alert.setTimeout(Alert.FOREVER);
d.setCurrent(alert);
}
}
I guess, that there's something wrong with my project.
P.S. the code above is not the project, of course