This discussion is archived
2 Replies Latest reply: Mar 31, 2010 8:52 PM by 807581 RSS

Persistence of data in J2ME mobile device using RMS

807581 Newbie
Currently Being Moderated
Hi. Just want to ensure that RMS can let us store some values in the mobile device. I'm using emulator to try this out. Everytime i close the emulator, the data stored in the RecordStore's gone. How about in real mobile device?
For some reasons, my jad and jar can't be installed in my Nokia 6210. It keeps giving me "Invalid Jar file" error.

So, my main question is whether RMS really stores the value in the mobile device and can be retrieved everytime that MIDlet app's run again.
The other question is why is it that my jar can't be installed in my Nokia 6210? I just built it with NetBean with J2ME and it could be run on the emulator perfectly.

Thanks a lot.
  • 1. Re: Persistence of data in J2ME mobile device using RMS
    807581 Newbie
    Currently Being Moderated
    Any data stored in RMS is deleted when you restart the emulator. If you exit the midlet and restart it, your RMS data should be preserved, but if you kill the emulator completely then you will loose it. Also, look in the emulator settings to see if there are any options for preserving state across emulator restarts.

    I'm not sure why you're having trouble with the Nokia. I would recommend trying to run a really simply HelloWorld midlet on the phone to see if it is some kind of packaging/deployment issue or something else. It might also be a security issue - you may have to configure the phone to disable signature checking, although the ability to do this varies from phone to phone.
  • 2. Re: Persistence of data in J2ME mobile device using RMS
    807581 Newbie
    Currently Being Moderated
    Hi. For the installation to my phone, i have solved it by changing my app's MIDP version 2.1 to 2.0.

    For the persistence of data part, i changed the Storage->"Storage Root Directory" to "\save" in Preferences of SJWTK and re-run my app on the emulator and my phone. However, it seems that the record store's data is not persisted. So, i assume it has something to do with my code. My code is as below. Can anyone give me some clues on what i have done wrong? Thanks.
    public TheConstructor(MIDlet midlet, Form form, int partnerId){
      ...
      
         try
         {
          // The second parameter indicates that the record store
          // should be created if it does not exist
            rs = RecordStore.openRecordStore(REC_STORE_NAME, true );
            if (rs.getNumRecords() == 0) {
                RecordIdParam = getAdsParam();
    
                if (clientIdParam.length > 0) {
                    clientId = RecordIdParam;
                    writeRecord(RecordIdParam);
                    readRecords();
                    closeRecStore();  // Close record sto
                }
    
            }
            else {
                readRecords();
                closeRecStore();  // Close
                
            }
         }
         catch (Exception e)
         {
          db(e.toString());
         }
      }
    
     private void db(String str)
      {
        System.err.println("Msg: " + str);
      }
    
     
      public void closeRecStore()
      {
        try
        {
          rs.closeRecordStore();
        }
        catch (Exception e)
        {
          db(e.toString());
        }
      }
    
       public void writeRecord(String str)
      {
        byte[] rec = str.getBytes();
    
        try
        {
          rs.addRecord(rec, 0, rec.length);
        }
        catch (Exception e)
        {
          db(e.toString());
        }
      }
    
      public void readRecords()
      {
        try
        {
          // Intentionally make this too small to test code below
          byte[] recData = new byte[5];
          int len;
    
          System.out.println("num of records is " + rs.getNumRecords());
    
          for (int i = 1; i <= rs.getNumRecords(); i++)
          {
            if (rs.getRecordSize(i) > recData.length)
              recData = new byte[rs.getRecordSize(i)];
    
            len = rs.getRecord(i, recData, 0);
    
            RecordIdParam = recData;
    
          }
        }
        catch (Exception e)
        {
          db(e.toString());
        }
      }