I am trying to create file using RMS. I couldn't use List Command to create a file using RMS. Can you suggest easier way to create a file using List.

import javax.microedition.midlet.*;
import javax.microedition.rms.*;
import javax.microedition.lcdui.*;


public class RmsNormal extends MIDlet implements CommandListener
{
    private Display disp;
    private Command exit;
    private List list;
    private Alert alert;
    private RecordStore recordstore = null;


public RmsNormal()
{
    disp = Display.getDisplay(this);
    exit = new Command("Exit", Command.EXIT, 1);
    list = new List("Menu", List.IMPLICIT);
    list.append("Create", null);
    list.append("Write", null);
    list.addCommand(exit);
    list.setCommandListener(this);
}
   
    protected void startApp()
    {   
    	disp.setCurrent(list);
    }
   
    protected void pauseApp()
    {
    }
   
    protected void destroyApp(boolean uncond)
    {   
    }
   
    public void commandAction(Command cmd, Displayable display)
    {
        if(cmd == List.SELECT_COMMAND)   
        {
            String selection = list.getString(list.getSelectedIndex());
        	// couldn't get idea to use List Command to Create File
            try
            {   
                recordstore = RecordStore.openRecordStore("RecorStore", true);
                alert = new Alert("File Created", null, null, AlertType.WARNING);
                alert.setTimeout(Alert.FOREVER);
                disp.setCurrent(alert);
            }
            catch (Exception error)
            {
                alert = new Alert("Error Removing", error.toString(), null, AlertType.WARNING);
                alert.setTimeout(Alert.FOREVER);
                disp.setCurrent(alert);
            }
           
            try
            {
                String outputData = "My";
                byte[] byteOutputData = outputData.getBytes();
                recordstore.addRecord(byteOutputData, 0, byteOutputData.length);
            }
            catch (Exception error)
            {
                alert = new Alert("Alert", error.toString(), null, AlertType.WARNING);
                alert.setTimeout(Alert.FOREVER);
                disp.setCurrent(alert);
            }
        }
        else if (cmd == exit)
        {
            destroyApp(true);
            notifyDestroyed();
        }
    }
}

Can you explain what you mean by these "couldn't get idea to use List Command to Create File"? I see you trying to do something with RecodStore, but these attempts are sort of half hearted.

How to store a value in RMS using List. When I click to list "create
button", actually I am trying to create a file using RMS method.

I can do with add Command. Is it possible to do List button, like Command button.

Sorry for miss-explanation of codes

if (cmd == create)
{
// Create file to Store values 
			
try 
{
recordstore = RecordStore.openRecordStore("Test", true);
alert = new Alert("Success", "File Created", null, AlertType.WARNING);
alert.setTimeout(Alert.FOREVER);
 display.setCurrent(alert);
}
catch (Exception error)
 {
 alert = new Alert("Error Creating", "Error Creating file"+ error.toString(), null, AlertType.WARNING);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert);
	}
}
  1. You either have to have RMS that is created by you and is full or you have access to know RMS and after that to read data. I see neither of that you pretend to open RMS and then nothing
  2. You handle RMS operation badly, you better to read this
  3. If you want to write a file you need to provide location where to store it, which obviously is missing and file create/write logic too.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.