?
Solved

maintain record store in J2ME

Posted on 2006-03-20
11
Medium Priority
?
294 Views
Last Modified: 2008-01-09
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..
0
Comment
Question by:redcoder
  • 7
  • 3
11 Comments
 
LVL 30

Accepted Solution

by:
Mayank S earned 750 total points
ID: 16243938
Have a look at these:

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

Can you post some code?
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16243940
0
 
LVL 13

Assisted Solution

by:bglodde
bglodde earned 750 total points
ID: 16244246
http://developers.sun.com/techtopics/mobility/midp/articles/persist/
Let us see what you're doing during your saves/updates.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:redcoder
ID: 16246473
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
 

Author Comment

by:redcoder
ID: 16246502
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
 

Author Comment

by:redcoder
ID: 16246508
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
 

Author Comment

by:redcoder
ID: 16246516
Basically I want to keepp few record... Then after that , I want to retrieve one record from those records kept earlier.

0
 

Author Comment

by:redcoder
ID: 16246533
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
 

Author Comment

by:redcoder
ID: 16246557
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
 
LVL 30

Expert Comment

by:Mayank S
ID: 16254439
>> Millionaire.pd.addNewRecord

Can we see that code? Also, what is Millionaire.instance and what is Millionaire.pd?
0
 

Author Comment

by:redcoder
ID: 16263155
Its is solve now.. I manage to get one record using getRecord().. from rms.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month9 days, 8 hours left to enroll

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question