maintain record store in J2ME

In J2ME, why the record store is not kept ? Everytiime i insert the record then close it and build it again and run .. The previous record is gone ... I have to re-insert the record again..
redcoderAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mayank SAssociate Director - Product EngineeringCommented:
Have a look at these:

http://java.sun.com/developer/J2METechTips/2001/tt0319.html

Can you post some code?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mayank SAssociate Director - Product EngineeringCommented:
0
bgloddeCommented:
http://developers.sun.com/techtopics/mobility/midp/articles/persist/
Let us see what you're doing during your saves/updates.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

redcoderAuthor Commented:
So far I am working on insert only..Updating will be later part.

I have class AddScreen.java :

      public AddScreen()
      {
      super("Add Record");
            
      try
      {
            submitCommand = new Command("Submit", Command.OK,0);
            backCommand = new Command("Back", Command.BACK,1);
                  
            //Prepare text field for user to enter
            //question, selection answer and correct answer
            question = new TextField("Question :     ","",50,TextField.ANY);                  
            answerA = new TextField("A:","",20,TextField.ANY);
            answerB = new TextField("B:","",20,TextField.ANY);
            answerC = new TextField("C:","",20,TextField.ANY);
            answerD = new TextField("D:","",20,TextField.ANY);                  
            correctAnswer = new TextField("Correct Answer:","",3,TextField.ANY);
            
            //add back and Submit at soft button
            addCommand(backCommand);
            addCommand(submitCommand);
                  
                  
            append("");
            append(question);
            append(answerA);
            append(answerB);
            append(answerC);
            append(answerD);
            append(correctAnswer);
                  
            setCommandListener(this);
            table = Millionaire.pd.readRecordStore();
            recStore = new ChoiceGroup("", ChoiceGroup.EXCLUSIVE, table, null);
            append(recStore);
      }
      catch (Exception e)
      {
                e.printStackTrace();                  
                }
            
      }

public void commandAction(Command c, Displayable d)
{
if(c == submitCommand)
{
      //assign each input in string datatype
      stquestion = question.getString();
      stansA = answerA.getString();
      stAnsB = answerB.getString();
      stAnsC = answerC.getString();
      stAnsD = answerD.getString();
      stCorrAns = correctAnswer.getString();
                  
      //add record to RecordStore
      Millionaire.pd.addNewRecord(stquestion+";"+stansA+";"+stAnsB+";"+stAnsC+";"+stAnsD+";"+stCorrAns);
System.out.println("Record Added");
}
else if(c == backCommand)
{
Display.getDisplay(Millionaire.instance).setCurrent(Millionaire.instance.getForm());
}
            
}


--------------------------
Then another class PersistantData.java that read the record:

  public String[] readRecordStore()
  {
    String table[] = null;

    try
    {
      int tablesize = recordStore.getNumRecords();
      table = new String[tablesize];
      int recordid;
      int i = 1;
      RecordEnumeration re = recordStore.enumerateRecords(null, null, false);
      while (re.hasNextElement())
      {
        recordid = re.nextRecordId();
        String res = new String(PersistantData.recordStore.getRecord(recordid));
        res += ";" + recordid;
        System.out.println("Record " + ":" + res);
        table[i - 1] = res;
        i++;
      }
      return table;
    }
    catch (Exception e)
    {
      e.printStackTrace();
      return table;
    }
  }
 
-------------------------------------


0
redcoderAuthor Commented:
The code above runs well ... It can show the record kept.. But when I add in the code below , it doesn't show all the records anymore:

  public String[] readOneRecordStore(int recNo)
  {
    String table[] = null;

    try
    {
      int tablesize = recordStore.getNumRecords();
      table = new String[tablesize];
      int recordid;
//      int i = 1;
      RecordEnumeration re = recordStore.enumerateRecords(null, null, false);
      while (re.hasNextElement())
      {
        recordid = re.nextRecordId();
        String res = new String(PersistantData.recordStore.getRecord(recordid));
        res += ";" + recordid;
        System.out.println("Record " + ":" + res);
        table[recNo - 1] = res;
//        i++;
      }
      return table;
    }
    catch (Exception e)
    {
      e.printStackTrace();
      return table;
    }
  }
0
redcoderAuthor Commented:
And this message appear on ToolKit panel...


java.lang.NullPointerException
      at javax.microedition.lcdui.ChoiceGroup.<init>(+92)
      at javax.microedition.lcdui.ChoiceGroup.<init>(+10)
      at AddScreen.<init>(+252)
      at Millionaire.commandAction(+38)
      at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(+282)
      at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(+10)
      at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(+68)
      at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(+47)
      at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+250)
0
redcoderAuthor Commented:
Basically I want to keepp few record... Then after that , I want to retrieve one record from those records kept earlier.

0
redcoderAuthor Commented:
These are the records I have kept in record store:

Record :Quest 9;Ans 9A;Ans 9B;Ans 9C;Ans 9D;B;9
Record :;;;;;;8
Record :Question 6;answer 1;answer 2;answer 3;answer 4;D;7
Record :Question 6;answer 1;answer 2;answer 3;answer 4;D;6
Record :Who are the pop king;MichealJackson;Elvis;Micheal jordan;David beckham;a;5
Record :asdasasd;as;asd;asd;asd;w;4
Record :sdfsfs;a;b;c;d;;3
Record :What is the slowest animal in the world?;Duck;Sloth;Cat;Dog;B;2
Record :Who create HTML?;Angelie;Barners Lee, Tim;Cynegie;Donald;B;1


Then I want to retrieve the record let say record 1. The number at the end of each record is the resord number. I will base on the number to retrieve the particular record.
0
redcoderAuthor Commented:
In addition to comment Date: 03/21/2006 05:30AM PST,

I also change the code in AddScreen.java :
form
table = Millionaire.pd.readRecordStore();  

to
table = Millionaire.pd.readOneRecordStore(2);
0
Mayank SAssociate Director - Product EngineeringCommented:
>> Millionaire.pd.addNewRecord

Can we see that code? Also, what is Millionaire.instance and what is Millionaire.pd?
0
redcoderAuthor Commented:
Its is solve now.. I manage to get one record using getRecord().. from rms.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.