Hi!
I am tryig to write a simple j2me MIDlet program.
Using that program, a user has to fill the required information to make an air reservation. And he also can see the resersation list.
I used the Recordstore to write and read again that reservation list. But my program does not show any list. I think It even does not write the list in the recordstore.
Where is the error?

Here is my program.
//ZSecondReservationMIDlet.java

package zsecondreservation;

import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

public class ZSecondReservationMIDlet extends MIDlet {
	
	static ZSecondReservationMIDlet zreservationmidlet;
	ZSecondReservationMainform zreservationmainform=new ZSecondReservationMainform("login From");
	Display display=Display.getDisplay(this);
	
	
	

	public ZSecondReservationMIDlet() {
		ZSecondReservationMIDlet.zreservationmidlet=this;
		
	}

	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
		// TODO Auto-generated method stub

	}

	protected void pauseApp() {
		// TODO Auto-generated method stub

	}

	protected void startApp() throws MIDletStateChangeException {
		display.setCurrent(zreservationmainform);
		
		// TODO Auto-generated method stub

	}

}

/////ReservationForm.java

package zsecondreservation;

import javax.microedition.lcdui.*;
//import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;

public class ReservationForm extends Form{
	TextField tfName=new TextField("Name","",7,TextField.ANY);
	ChoiceGroup cgFrom=new ChoiceGroup("From",ChoiceGroup.POPUP);
	ChoiceGroup cgTo=new ChoiceGroup("To",ChoiceGroup.POPUP);
	DateField  cgDate=new DateField("Date",DateField.DATE_TIME);
	ChoiceGroup cgTime=new ChoiceGroup("Time",ChoiceGroup.EXCLUSIVE);
	ChoiceGroup cgFood=new ChoiceGroup("Food",ChoiceGroup.EXCLUSIVE);
	TextField tfMobile=new TextField("Mobile no","",9,TextField.PHONENUMBER);
	Command cmdLogout=new Command("Logout",Command.SCREEN,0);
	Command cmdBook=new Command("Book",Command.SCREEN,0);
	Command cmdDisplayBookingList=new Command("DisplayBookingList",Command.SCREEN,0);
	

	public ReservationForm(String s) {
		super(s);
		append(tfName);
		cgFrom.append("Singapore",null);
		
		cgFrom.append("Bangkok",null);
		append(cgFrom);
		cgTo.append("Tokyo",null);
		cgTo.append("Seoul",null);
		append(cgTo);
		append(cgDate);
		cgTime.append("Morning", null);
		cgTime.append("Evening", null);
		append(cgTime);
		cgFood.append("Veg",null);
		cgFood.append("non-veg",null);
		append(cgFood);
		append(tfMobile);
		addCommand(cmdLogout);
		addCommand(cmdBook);
		addCommand(cmdDisplayBookingList);
		setCommandListener(new ReservationCommandHandler());
		
		
	}

}

//////ReservationCommandHandler.java

package zsecondreservation;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.rms.RecordEnumeration;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;

public class ReservationCommandHandler implements CommandListener {

	public ReservationCommandHandler() {
		// TODO Auto-generated constructor stub
	}

	public void commandAction(Command c, Displayable d) {
		
		ReservationForm reservationform=(ReservationForm)d;
		//ZSecondReservationMainform zreservationmainform=new ZSecondReservationMainform("login From");
	    RecordStore recordstore=null;
	    RecordEnumeration recordenumeration=null;
		
		if(c==reservationform.cmdLogout)
		{
			ZSecondReservationMainform zreservationmainform=new ZSecondReservationMainform("login From");
			Display display=Display.getDisplay(ZSecondReservationMIDlet.zreservationmidlet);
			display.setCurrent(zreservationmainform);
		}
		
		if(c==reservationform.cmdBook)
		{
			try {
				recordstore=RecordStore.openRecordStore("reservation list",true);
				
			} catch (RecordStoreException e) {
				// TODO Auto-generated catch block
				//e.printStackTrace();
				Alert alert=new Alert("Error Creating",e.toString(),null,AlertType.ERROR);
				Display display=Display.getDisplay(ZSecondReservationMIDlet.zreservationmidlet);
				display.setCurrent(alert);
				
				
			}
			byte[] OutputRecord;
			ByteArrayOutputStream outputstream=new ByteArrayOutputStream();
			DataOutputStream outputdatastream=new DataOutputStream(outputstream);
			try {
				outputdatastream.writeUTF(reservationform.tfName.getString());
				outputdatastream.writeInt(reservationform.cgFrom.getSelectedIndex());
				outputdatastream.writeInt(reservationform.cgTo.getSelectedIndex());
				outputdatastream.flush();
				OutputRecord=outputstream.toByteArray();
				recordstore.addRecord(OutputRecord, 0, OutputRecord.length);
				Alert alert=new Alert("Reservation completed","Have a nice trip!",null,AlertType.INFO);
				Display display=Display.getDisplay(ZSecondReservationMIDlet.zreservationmidlet);
				
				display.setCurrent(alert);
				
				outputstream.reset();
				outputstream.close();
				outputdatastream.close();
				
			} catch (IOException e) {
				// TODO Auto-generated catch block
				//e.printStackTrace();
				Alert alert=new Alert("Error writing",e.toString(),null,AlertType.ERROR);
				Display display=Display.getDisplay(ZSecondReservationMIDlet.zreservationmidlet);
				display.setCurrent(alert);
				
			} catch (RecordStoreException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
		if(c==reservationform.cmdDisplayBookingList)
			
		{
			Alert alert=new Alert("*******","****",null,AlertType.INFO);////////////////
			Display display=Display.getDisplay(ZSecondReservationMIDlet.zreservationmidlet);///////////
			display.setCurrent(alert);/////////////
			
			try {
				StringBuffer buffer=new StringBuffer();
				recordstore=RecordStore.openRecordStore("reservation list",false);
				recordenumeration=recordstore.enumerateRecords(null, null, true);
				byte[] byteinputdata=new byte[300];
				ByteArrayInputStream inputstream=new ByteArrayInputStream(byteinputdata);
				DataInputStream datainputstream=new DataInputStream(inputstream);
				
				
				while(recordenumeration.hasNextElement())
				{
					
					 			
					
					recordstore.getRecord(recordenumeration.nextRecordId(),byteinputdata, 0);
					try {
						buffer.append(datainputstream.readUTF());
						buffer.append("\n");
						buffer.append(datainputstream.readInt());
						buffer.append("\n");
						buffer.append(datainputstream.readInt());
						buffer.append("\n");
						 alert=new Alert("Reservatin List",buffer.toString(),null,AlertType.INFO);
						 display=Display.getDisplay(ZSecondReservationMIDlet.zreservationmidlet);
						 display.setCurrent(alert);
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					
				}
					
				
		} catch (RecordStoreException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

}

////ReservationMainForm.java

package zsecondreservation;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;

public class ZSecondReservationMainform extends Form{
	TextField txtname=new TextField("Name","",7,TextField.ANY);
	TextField txtpassword=new TextField("Password","",7,TextField.PASSWORD);
	Command cmdlogin=new Command("Login",Command.SCREEN,1);
	Command cmdexit=new Command("Exit",Command.EXIT,0);

	public ZSecondReservationMainform(String title) {
		super(title);
		append(txtname);
		append(txtpassword);
		addCommand(cmdlogin);
		addCommand(cmdexit);
		setCommandListener(new LoginCommandHandlar());
		
		
		// TODO Auto-generated constructor stub
	}

}

///////LoginCommandHandlar.java

package zsecondreservation;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;

public class LoginCommandHandlar implements CommandListener {
	//Alert alert;
	//Display display=Display.getDisplay(ZSecondReservationMIDlet.zreservationmidlet);

	public LoginCommandHandlar() {
		// TODO Auto-generated constructor stub
	}

	public void commandAction(Command c, Displayable d) {
		ZSecondReservationMainform zloginform =(ZSecondReservationMainform)d;
		
		
		if(c==zloginform.cmdexit)
		{ 
			ZSecondReservationMIDlet.zreservationmidlet.notifyDestroyed();
			
		}
		// TODO Auto-generated method stub
		if(c==zloginform.cmdlogin)
		{
			Display display=Display.getDisplay(ZSecondReservationMIDlet.zreservationmidlet);
			Alert alert;
			
			if(zloginform.txtname.getString().equals("name")&&zloginform.txtpassword.getString().equals("password"))
			{
				ReservationForm reservationform= new ReservationForm("Reservation Form");
				alert=new Alert("Correct","Login is successful",null,AlertType.INFO);
				 display.setCurrent(alert,reservationform);
				
			}
			
			else
			{
				  alert=new Alert("Incorrect","Try again",null,AlertType.ERROR);
				  zloginform.txtname.setString("");
				  zloginform.txtpassword.setString("");
				  display.setCurrent(alert);
				  
			}
				
			//display.setCurrent(alert);	
		}

	}

}

Hi!
No one replied to my last question because of my mistake. I did not ask clearly what I want to know and posted complex unsystematic code that are not necessary to show here. I am very sorry to distrub u all.
I have modified my program as follows.
User can enter data and that will be stored in a Recordstore when the user clicked the book command. All input records will be shown when the user chooses the displayreservation list command.
But my program can show only one record and it just shows only the blank for the rest of the records in the recordstore.

And my program does not store that data permanently in the Recordstore. Whenever I close the program, that data are lost. I have to enter that data again.

What are the errors? Please help me.

package zsecondreservation;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.rms.RecordEnumeration;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;

public class ReservationCommandHandler implements CommandListener {

	public ReservationCommandHandler() {
		// TODO Auto-generated constructor stub
	}

	public void commandAction(Command c, Displayable d) {
		
		ReservationForm reservationform=(ReservationForm)d;
		RecordStore recordstore=null;
	    RecordEnumeration recordenumeration=null;
		
		if(c==reservationform.cmdLogout)
		{
			ZSecondReservationMainform zreservationmainform=new ZSecondReservationMainform("login From");
			Display display=Display.getDisplay(ZSecondReservationMIDlet.zreservationmidlet);
			display.setCurrent(zreservationmainform);
		}
		
		if(c==reservationform.cmdBook)
		{
			try {
				recordstore=RecordStore.openRecordStore("reservationlist",true);
				
			} catch (RecordStoreException e) {
				Alert alert=new Alert("Error Creating",e.toString(),null,AlertType.ERROR);
				Display display=Display.getDisplay(ZSecondReservationMIDlet.zreservationmidlet);
				display.setCurrent(alert);
				
				
			}
			byte[] OutputRecord;
			ByteArrayOutputStream outputstream=new ByteArrayOutputStream();
			DataOutputStream outputdatastream=new DataOutputStream(outputstream);
			try {
				outputdatastream.writeUTF(reservationform.tfName.getString());
				outputdatastream.writeUTF(reservationform.cgFrom.getString(reservationform.cgFrom.getSelectedIndex()));
				outputdatastream.writeUTF(reservationform.cgTo.getString(reservationform.cgTo.getSelectedIndex()));
				outputdatastream.flush();
				
				OutputRecord=outputstream.toByteArray();
				System.out.println(OutputRecord);
				recordstore.addRecord(OutputRecord, 0, OutputRecord.length);
				Alert alert=new Alert("Reservation completed","Have a nice trip!",null,AlertType.INFO);
				Display display=Display.getDisplay(ZSecondReservationMIDlet.zreservationmidlet);
				
				display.setCurrent(alert);
				
				outputstream.reset();
				outputstream.close();
				outputdatastream.close();
				/////////////
				reservationform.tfName.setString("");
			} catch (IOException e) {				
				Alert alert=new Alert("Error writing",e.toString(),null,AlertType.ERROR);
				Display display=Display.getDisplay(ZSecondReservationMIDlet.zreservationmidlet);
				display.setCurrent(alert);
				
			} catch (RecordStoreException e) {				
				e.printStackTrace();
			}
			
		}
		if(c==reservationform.cmdDisplayBookingList)
			
		{
			
			Display display=Display.getDisplay(ZSecondReservationMIDlet.zreservationmidlet); 
			try {
				StringBuffer buffer=new StringBuffer();
				recordstore=RecordStore.openRecordStore("reservationlist",true);				
				recordenumeration=recordstore.enumerateRecords(null, null, false);
				byte[] byteinputdata=new byte[300];
				ByteArrayInputStream inputstream=new ByteArrayInputStream(byteinputdata);
				DataInputStream datainputstream=new DataInputStream(inputstream);
				
				
				while(recordenumeration.hasNextElement())
				{					
					recordstore.getRecord(recordenumeration.nextRecordId(),byteinputdata, 0);
					try {
						
						buffer.append(datainputstream.readUTF());
						buffer.append("\n");
						buffer.append(datainputstream.readUTF());
						buffer.append("\n");
						buffer.append(datainputstream.readUTF());
						buffer.append("\n");						 
					} catch (IOException e) {
						
						e.printStackTrace();
					}
					
					
				}//while
				Alert alert1=new Alert("Reservatin List",buffer.toString(),null,AlertType.INFO);
				display.setCurrent(alert1);	
				
		} catch (RecordStoreException e) {
				
				e.printStackTrace();
			}
		}
	}

}

Hi!
No one replied to my last question because of my mistake. I did not ask clearly what I want to know and posted complex unsystematic code that are not necessary to show here. I am very sorry to distrub u all.
I have modified my program as follows.
User can enter data and that will be stored in a Recordstore when the user clicked the book command. All input records will be shown when the user chooses the displayreservation list command.
But my program can show only one record and it just shows only the blank for the rest of the records in the recordstore.

And my program does not store that data permanently in the Recordstore. Whenever I close the program, that data are lost. I have to enter that data again.

What are the errors? Please help me.

package zsecondreservation;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.rms.RecordEnumeration;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;

public class ReservationCommandHandler implements CommandListener {

	public ReservationCommandHandler() {
		// TODO Auto-generated constructor stub
	}

	public void commandAction(Command c, Displayable d) {
		
		ReservationForm reservationform=(ReservationForm)d;
		RecordStore recordstore=null;
	    RecordEnumeration recordenumeration=null;
		
		if(c==reservationform.cmdLogout)
		{
			ZSecondReservationMainform zreservationmainform=new ZSecondReservationMainform("login From");
			Display display=Display.getDisplay(ZSecondReservationMIDlet.zreservationmidlet);
			display.setCurrent(zreservationmainform);
		}
		
		if(c==reservationform.cmdBook)
		{
			try {
				recordstore=RecordStore.openRecordStore("reservationlist",true);
				
			} catch (RecordStoreException e) {
				Alert alert=new Alert("Error Creating",e.toString(),null,AlertType.ERROR);
				Display display=Display.getDisplay(ZSecondReservationMIDlet.zreservationmidlet);
				display.setCurrent(alert);
				
				
			}
			byte[] OutputRecord;
			ByteArrayOutputStream outputstream=new ByteArrayOutputStream();
			DataOutputStream outputdatastream=new DataOutputStream(outputstream);
			try {
				outputdatastream.writeUTF(reservationform.tfName.getString());
				outputdatastream.writeUTF(reservationform.cgFrom.getString(reservationform.cgFrom.getSelectedIndex()));
				outputdatastream.writeUTF(reservationform.cgTo.getString(reservationform.cgTo.getSelectedIndex()));
				outputdatastream.flush();
				
				OutputRecord=outputstream.toByteArray();
				System.out.println(OutputRecord);
				recordstore.addRecord(OutputRecord, 0, OutputRecord.length);
				Alert alert=new Alert("Reservation completed","Have a nice trip!",null,AlertType.INFO);
				Display display=Display.getDisplay(ZSecondReservationMIDlet.zreservationmidlet);
				
				display.setCurrent(alert);
				
				outputstream.reset();
				outputstream.close();
				outputdatastream.close();
				/////////////
				reservationform.tfName.setString("");
			} catch (IOException e) {				
				Alert alert=new Alert("Error writing",e.toString(),null,AlertType.ERROR);
				Display display=Display.getDisplay(ZSecondReservationMIDlet.zreservationmidlet);
				display.setCurrent(alert);
				
			} catch (RecordStoreException e) {				
				e.printStackTrace();
			}
			
		}
		if(c==reservationform.cmdDisplayBookingList)
			
		{
			
			Display display=Display.getDisplay(ZSecondReservationMIDlet.zreservationmidlet); 
			try {
				StringBuffer buffer=new StringBuffer();
				recordstore=RecordStore.openRecordStore("reservationlist",true);				
				recordenumeration=recordstore.enumerateRecords(null, null, false);
				byte[] byteinputdata=new byte[300];
				ByteArrayInputStream inputstream=new ByteArrayInputStream(byteinputdata);
				DataInputStream datainputstream=new DataInputStream(inputstream);
				
				
				while(recordenumeration.hasNextElement())
				{					
					recordstore.getRecord(recordenumeration.nextRecordId(),byteinputdata, 0);
					try {
						
						buffer.append(datainputstream.readUTF());
						buffer.append("\n");
						buffer.append(datainputstream.readUTF());
						buffer.append("\n");
						buffer.append(datainputstream.readUTF());
						buffer.append("\n");						 
					} catch (IOException e) {
						
						e.printStackTrace();
					}
					
					
				}//while
				Alert alert1=new Alert("Reservatin List",buffer.toString(),null,AlertType.INFO);
				display.setCurrent(alert1);	
				
		} catch (RecordStoreException e) {
				
				e.printStackTrace();
			}
		}
	}

}

the problem might be
u have put alert outside the while loop so it reads the whole database in while then comes out
and displays the last record with the .getString() function
and the blank is the remaining space of byte array[300]
so manupilate that a bit
also try this for record store getting deleted i am even not sure here
don't declare it in command action but above it and before reservation command handler;

also better to close and reset the input stream and data inputstream if possible

reply if it gets solved

If you post updated code I will have look at it (presuming that yo already found and solved login problem with password ;) )

Hi,
Thanks for your kind replies. But I still didn’t get it.
I put the alert outside the while loop because I want to show the entire booking.
And the record shown by my program is not the last record. It only shows the first record and blank for the rest. I can say that it shows the blank because I append the string “What is the problem?” to the buffer after the while loop.
For example, if the first record I book is John, Tokyo, Newyork, then if I choose displaybookinglist command, the program shows like that
John
Tokyo
Newyork
What is the problem?

After that , if I book the second record, Thomas, Tokyo, Seoul, then if I choose displaybookinglist command, the program shows like that
John
Tokyo
Newyork
[blank here]
[blank here]
[blank here]
What is the problem?

As you suggest me, I put the alert box in the while loop. But it does not work.
And I declared the RecordStore and RecordEnumeration above the command action.
And I have also closed the recordstore. Here is my a little updated coding.

What is the problem?
Please help me.

package zsecondreservation;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.rms.RecordEnumeration;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;

public class ReservationCommandHandler implements CommandListener {
	RecordStore recordstore=null;
    RecordEnumeration recordenumeration=null;

	public ReservationCommandHandler() {
		// TODO Auto-generated constructor stub
	}

	public void commandAction(Command c, Displayable d) {
		
		ReservationForm reservationform=(ReservationForm)d;
		//RecordStore recordstore=null;
	    //RecordEnumeration recordenumeration=null;
		
		if(c==reservationform.cmdLogout)
		{
			ZSecondReservationMainform zreservationmainform=new ZSecondReservationMainform("login From");
			Display display=Display.getDisplay(ZSecondReservationMIDlet.zreservationmidlet);
			display.setCurrent(zreservationmainform);
		}
		
		if(c==reservationform.cmdBook)
		{
			try {
				recordstore=RecordStore.openRecordStore("reservationlist",true);
				
			} catch (RecordStoreException e) {
				Alert alert=new Alert("Error Creating",e.toString(),null,AlertType.ERROR);
				Display display=Display.getDisplay(ZSecondReservationMIDlet.zreservationmidlet);
				display.setCurrent(alert);
				
				
			}
			byte[] OutputRecord;
			ByteArrayOutputStream outputstream=new ByteArrayOutputStream();
			DataOutputStream outputdatastream=new DataOutputStream(outputstream);
			try {
				outputdatastream.writeUTF(reservationform.tfName.getString());
				System.out.println(reservationform.tfName.getString());
				outputdatastream.writeUTF(reservationform.cgFrom.getString(reservationform.cgFrom.getSelectedIndex()));
				outputdatastream.writeUTF(reservationform.cgTo.getString(reservationform.cgTo.getSelectedIndex()));
				outputdatastream.flush();
				
				OutputRecord=outputstream.toByteArray();
				//System.out.println(outputstream.toString());
				System.out.println(String.valueOf(OutputRecord));
				
				recordstore.addRecord(OutputRecord, 0, OutputRecord.length);
				Alert alert=new Alert("Reservation completed","Have a nice trip!",null,AlertType.INFO);
				Display display=Display.getDisplay(ZSecondReservationMIDlet.zreservationmidlet);
				
				display.setCurrent(alert);
				
				outputstream.reset();
				outputstream.close();
				outputdatastream.close();
				/////////////
				reservationform.tfName.setString("");
			} catch (IOException e) {				
				Alert alert=new Alert("Error writing",e.toString(),null,AlertType.ERROR);
				Display display=Display.getDisplay(ZSecondReservationMIDlet.zreservationmidlet);
				display.setCurrent(alert);
				
			} catch (RecordStoreException e) {
				Alert alert=new Alert("************",e.toString(),null,AlertType.ERROR);
				Display display=Display.getDisplay(ZSecondReservationMIDlet.zreservationmidlet);
				display.setCurrent(alert);
				e.printStackTrace();
			}
			
			finally
			{
				try {
					recordstore.closeRecordStore();
				} catch (RecordStoreException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		
		}
		if(c==reservationform.cmdDisplayBookingList)
			
		{
			
			Display display=Display.getDisplay(ZSecondReservationMIDlet.zreservationmidlet); 
			try {
				StringBuffer buffer=new StringBuffer();
				recordstore=RecordStore.openRecordStore("reservationlist",true);				
				recordenumeration=recordstore.enumerateRecords(null, null, false);
				byte[] byteinputdata=new byte[300];
				ByteArrayInputStream inputstream=new ByteArrayInputStream(byteinputdata);
				DataInputStream datainputstream=new DataInputStream(inputstream);
				
				
				while(recordenumeration.hasNextElement())
				{					
					recordstore.getRecord(recordenumeration.nextRecordId(),byteinputdata, 0);
					try {
						String test=datainputstream.readUTF();
						
						System.out.println(test);
						//else buffer.append(test);
						buffer.append(test);
						//System.out.println(test);
						//buffer.append(datainputstream.readUTF());
						buffer.append("\n");
						buffer.append(datainputstream.readUTF());
						buffer.append("\n");
						buffer.append(datainputstream.readUTF());
						buffer.append("\n");
						
						//Alert alert1=new Alert("Reservatin List",buffer.toString(),null,AlertType.INFO);/////////////////
						//alert1.setTimeout(Alert.FOREVER);
						//display.setCurrent(alert1);	/////////////////////////
						//buffer.delete(0, buffer.length());/////////////
					} catch (IOException e) {
						
						e.printStackTrace();
					}
					
					
				}//while
				buffer.append("what is the problem?");
				
				Alert alert1=new Alert("Reservatin List",buffer.toString(),null,AlertType.INFO);/////////////////
				display.setCurrent(alert1);	/////////////////////////
				System.out.println(buffer.toString());
				
				try {
					inputstream.close();
					datainputstream.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
		} catch (RecordStoreException e) {
				
				e.printStackTrace();
			}
		
		finally
		{
			try {
				recordstore.closeRecordStore();
			} catch (RecordStoreException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		}
		
	}

}

If you post updated code I will have look at it (presuming that yo already found and solved login problem with password ;) )

Check this correction

if (c == reservationform.cmdDisplayBookingList){

            Display display = Display.getDisplay(ZSecondReservationMIDlet.zreservationmidlet);
            try {
                StringBuffer buffer = new StringBuffer();
                recordstore = RecordStore.openRecordStore("reservationlist", true);
                recordenumeration = recordstore.enumerateRecords(null, null, false);
                byte[] byteinputdata;
                ByteArrayInputStream inputstream;
                DataInputStream datainputstream;


                while (recordenumeration.hasNextElement()) {
                    int i = recordenumeration.nextRecordId();
                    byteinputdata = recordstore.getRecord(i);
                    try {
                        inputstream = new ByteArrayInputStream(byteinputdata);
                        datainputstream = new DataInputStream(inputstream);
                        String test = datainputstream.readUTF();

                        System.out.println(test);
                        //else buffer.append(test);
                        buffer.append(test);
                        //System.out.println(test);
                        //buffer.append(datainputstream.readUTF());
                        buffer.append("\n");
                        buffer.append(datainputstream.readUTF());
                        buffer.append("\n");
                        buffer.append(datainputstream.readUTF());
                        buffer.append("\n");

                        //Alert alert1=new Alert("Reservatin List",buffer.toString(),null,AlertType.INFO);/////////////////
                        //alert1.setTimeout(Alert.FOREVER);
                        //display.setCurrent(alert1);	/////////////////////////
                        //buffer.delete(0, buffer.length());/////////////

                        inputstream.close();
                        datainputstream.close();
                    } catch (IOException e) {

                        e.printStackTrace();
                    }


                }//while

                Alert alert1 = new Alert("Reservatin List", buffer.toString(), null, AlertType.INFO);/////////////////
                display.setCurrent(alert1);    /////////////////////////
                System.out.println(buffer.toString());

            } catch (RecordStoreException e) {

                e.printStackTrace();
            }

            finally {
                try {
                    recordstore.closeRecordStore();
                } catch (RecordStoreException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }

If you want have look on Contact sorting - Contact List, Part 3 article/tutorial that I wrote some time ago. It does show how to work with RecordStore, also you will see how to more efficiently organize your application

Hi
Thank you very much, Peter_budo.
Now, the program shows all the records very beautifullyyy. You helped a lot to me.

But I am still confused. Even if I did not create new instance of DataInputStream and ByteArrayInputStream, I think the program should not show the blank for the next records. It should show just the first record as the data of the other records[ the data that has been in the DataInputStream]. Why it shows the blank?
Here is the program I wrote before this reservation program. There is no difference between these two programs in the part of reading recordstore.
I don’t create new instance of DataInputStream and ByteArrayInputStream in that program but it shows all the records. Why?

I am sorry if my question is a very stupid one. May be it is because I don’t understand about the concept of stream. Please point out if there is any tutorial or book I should read about that.

package zbmixedrecordenumeration;

import java.io.*;

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

public class CommandHandler implements CommandListener {
	RecordStore recordstore=null;
	RecordEnumeration recordenumeration=null;
	Alert alert;
	Display display;

	public CommandHandler() {
		// TODO Auto-generated constructor stub
	}

	public void commandAction(Command c, Displayable d) {
		MainForm mainform=(MainForm)d;
		if(c==mainform.cmdExit)
		{
			try {
				MixedRecordMIDlet.mixedrecordmidlet.destroyApp(true);
			} catch (MIDletStateChangeException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			MixedRecordMIDlet.mixedrecordmidlet.notifyDestroyed();
		}
		
		if(c==mainform.cmdWrite)
		{
			byte[] outputRecord=null;
			String outputString[]={"First Record","Second Record","Third Record"};
			String test[]={"aa","bb","cc"};
			String test2[]={"a1","b1","c1"};
			//int outputInteger[]={1,2,3};
			//boolean outputBoolean[]={true,false,true};
			ByteArrayOutputStream outputStream=new ByteArrayOutputStream();
			DataOutputStream outputDataStream=new DataOutputStream(outputStream);
			
			try {
				recordstore=RecordStore.openRecordStore("recordlist", true);
			} catch (RecordStoreException e) {
				alert=new Alert("opening Error",e.toString(),null,AlertType.INFO);
				display=Display.getDisplay(MixedRecordMIDlet.mixedrecordmidlet);
				display.setCurrent(alert);				
			}
			
			for(int x=0;x<3;x++)
			{
				
					try {
						outputDataStream.writeUTF(outputString[x]);
						outputDataStream.writeUTF(test[x]);
						outputDataStream.writeUTF(test2[x]);
						//outputDataStream.writeInt(outputInteger[x]);
						//outputDataStream.writeBoolean(outputBoolean[x]);
						outputDataStream.flush();
						outputRecord=outputStream.toByteArray();
						
						
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					try {
						recordstore.addRecord(outputRecord, 0, outputRecord.length);
					} catch (RecordStoreException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					
					
				
			}
			outputStream.reset();
			
			try {
				outputStream.close();
				outputDataStream.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}			
			
		}////////////////
		
		
		if(c==mainform.cmdRead)
		{
			StringBuffer buffer=new StringBuffer();
			byte[] byteInputData=new byte[300];///////////////////////
			ByteArrayInputStream inputStream=new ByteArrayInputStream(byteInputData);
			DataInputStream inputDataStream=new DataInputStream(inputStream);
			try {
				recordstore=RecordStore.openRecordStore("recordlist", false);
			} catch (RecordStoreException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			try {
				recordenumeration=recordstore.enumerateRecords(null, null, false);
			} catch (RecordStoreNotOpenException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			while(recordenumeration.hasNextElement())
			{
				try {
					
					recordstore.getRecord(recordenumeration.nextRecordId(), byteInputData, 0);
					buffer.append(inputDataStream.readUTF());
					buffer.append("\n");
					buffer.append(inputDataStream.readUTF());
					//buffer.append(inputDataStream.readInt());
					buffer.append("\n");
					buffer.append(inputDataStream.readUTF());
					//buffer.append(inputDataStream.readBoolean());
					buffer.append("\n");
					
				} catch (RecordStoreException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				
			}//while
			alert=new Alert("list",buffer.toString(),null,AlertType.INFO);
			display=Display.getDisplay(MixedRecordMIDlet.mixedrecordmidlet);
			display.setCurrent(alert);	
			
			
			try {
				recordstore.closeRecordStore();
			} catch (RecordStoreException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			
		}/////if(c==mainform.cmdRead)
		
		
		

	}

}
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.