×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Registered User
    Join Date
    Oct 2007
    Location
    Noida
    Posts
    152

    cannot access RMS from midilet suite

    Hello PPl,

    I just created two midilet in a same application. I am using one midilet to write into the RMS and i want to read the RMS using the other one. I am using the following code. I am able to read the contents after writing in it using the same midilet but i am not able to read the RMS data from another midilet.

    please have a look at the source code.

    this code writes the data using midlet A (this works)
    Code:
    rs_choiceFCCatFVS = RecordStore.openRecordStore(table_name,true,RecordStore.AUTHMODE_ANY,true);
    
    byte[] byte_FCCatFVS = "jingle bell jingle bell jingle all the way.. ho ho ho ".getBytes();
    
    rs_choiceFCCatFVS.addRecord(byte_FCCatFVS,0,byte_FCCatFVS.length);
    This code reads the data in Midlet A (this works)
    Code:
     byte[] byteFCCstFVS = new byte[300];
     int len;
     len = rs_choiceFCCatFVS.getRecord(1, byteFCCstFVS, 0);
     strFCCatFVS = new String(byteFCCstFVS, 0, len);
     strFCCatFVS.trim();
    next when i try to read the same thing from another midlet it is not working
    Code:
        byte[] byte_Extraceted = new byte[300];
            
            try
            {
                rs_Main.openRecordStore(table_name,true);
                int len = rs_Main.getRecord(1,byte_Extraceted,0);
                strExtractedData = new String(byte_Extraceted,0,len);
                form.append(strExtractedData);
                form.append("after data is appended");
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
    It is giving me null pointer error in "int len = rs_Main.getRecord(1,byte_Extraceted,0);" line ...

    some help please

    thanks in Advance
    Abhishek karmakar

    never- Never - NEVER -- !!! NEVER !!! GIVE UP

  2. #2
    Regular Contributor
    Join Date
    Sep 2007
    Location
    Thirunelveli
    Posts
    115

    Re: cannot access RMS from midilet suite

    Hi,

    There is no need to make the recordstore shareable to access inside the MidletSuite. in both midlet use the normal code of opening the RMS. i beleive this will work
    Please try to opent the recordstore with not creatable ie
    rs_Main.openRecordStore(table_name,false); in Midlet B and

    rs_Main.openRecordStore(table_name,true); in Midlet A

    please try and tell me if it works

    Regards
    Senthil

  3. #3
    Super Contributor
    Join Date
    Sep 2008
    Location
    Noida, U.P.
    Posts
    1,330

    Thumbs up Re: cannot access RMS from midilet suite

    Hi,
    Quote Originally Posted by senthil_k View Post
    Hi,

    There is no need to make the recordstore shareable to access inside the MidletSuite. in both midlet use the normal code of opening the RMS. i beleive this will work
    Please try to opent the recordstore with not creatable ie
    rs_Main.openRecordStore(table_name,false); in Midlet B and

    rs_Main.openRecordStore(table_name,true); in Midlet A

    please try and tell me if it works

    Regards
    Senthil
    parameter "true" tends to create Recordstore if not exists. Then no need to set it false coz if Midlet B can access then no effect produce if we pass "true" in Midlet B to open recordstore. So "true " or "false " not matters coz if recordstore created once then no matters what will be the parameter "true" or "false". Its matter just at the creation of recordstore. After creation doesn't matters. Well I have tested ur problem but i dont found any wrong. Recordstore is being shareable with both the midlets.

    do u found any exception. Did u handle the exceptions and yes then if any exceptuion is there then what it is? Please reply. check ur application again on device by removing it and reinstalling it.
    thanks,
    jitu_goldie..

    KEEP TRYING..

  4. #4
    Registered User
    Join Date
    Oct 2007
    Location
    Noida
    Posts
    152

    Re: cannot access RMS from midilet suite

    Hi Senthil_K,
    There is no need to make the recordstore shareable to access inside the MidletSuite. in both midlet use the normal code of opening the RMS. i beleive this will work
    I tried that earlier but that is also not working.

    I tested the same on wtk2.5 emulator and a real phone as well but it does not seem to work.

    Any other ideas.

    regards.
    Abhishek
    Abhishek karmakar

    never- Never - NEVER -- !!! NEVER !!! GIVE UP

  5. #5
    Registered User
    Join Date
    Oct 2007
    Location
    Noida
    Posts
    152

    Re: cannot access RMS from midilet suite

    Hi jitu_goldie,
    when i try this line
    Code:
    rs_Main.openRecordStore(table_name,false);
    it gives me a "javax.microedition.rms.RecordStoreNotFoundException: cannot find record store file" error..


    when i try this line it gives me Null pointer exception.
    Code:
    rs_Main.openRecordStore(table_name,true);
     int len = rs_Main.getRecord(1,byte_Extraceted,0);
    i noticed one more thing. A RMS is basically created inside the appdb of the emulator forlder inside."C:\Documents and Settings\[username]\.netbeans\5.5.1\emulators\wtk251-win\emulator\appdb\DefaultColorPhone" but i am able to see when i run Midlet A. But it vanishes as soon as i close the midlet. So its pretty obvious that the other midlet cannot search it.

    by the way thanks a lot for the replies ..
    Last edited by Abhishek_karmakar; 2009-03-26 at 12:12. Reason: updated description
    Abhishek karmakar

    never- Never - NEVER -- !!! NEVER !!! GIVE UP

  6. #6
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: cannot access RMS from midilet suite

    Are these midlets in the same JAR file, or separate JARs?

  7. #7
    Registered User
    Join Date
    Oct 2007
    Location
    Noida
    Posts
    152

    Re: cannot access RMS from midilet suite

    @grahamhughes
    They are in the same JAR

    regards
    Abhishek
    Abhishek karmakar

    never- Never - NEVER -- !!! NEVER !!! GIVE UP

  8. #8
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: cannot access RMS from midilet suite

    Quote Originally Posted by Abhishek_karmakar View Post
    i noticed one more thing. A RMS is basically created inside the appdb of the emulator forlder inside."C:\Documents and Settings\[username]\.netbeans\5.5.1\emulators\wtk251-win\emulator\appdb\DefaultColorPhone" but i am able to see when i run Midlet A. But it vanishes as soon as i close the midlet. So its pretty obvious that the other midlet cannot search it.
    Ah... in the emulator, rms is temporary, unless you install the application into the emulator, like:

    Code:
    emulator -Xjam:install=myapp.jad
    Check the emulator documentation for this.

    On the device, of course, RMS is persistent, until the MIDlet suite is uninstalled.

  9. #9
    Registered User
    Join Date
    Oct 2007
    Location
    Noida
    Posts
    152

    Re: cannot access RMS from midilet suite

    but i tried it inside my phone also .. and it dosent seem to work.

    is there something else i need to look at .
    Abhishek karmakar

    never- Never - NEVER -- !!! NEVER !!! GIVE UP

  10. #10
    Regular Contributor
    Join Date
    Sep 2007
    Location
    Thirunelveli
    Posts
    115

    Re: cannot access RMS from midilet suite

    Hi,
    There is a possibility that when each time emulator is exited the RMS can be cleared. will the rms cleared when exits the midlet and still in the midlet suite.

    The response given clearly shows that the recordstore is not available when the recordstore is accessed by another midlet

    Abhishek one more guess just a suggetion not sure is the length of the byte array is correct that is it is only 300 needed



    Senthil
    Last edited by senthil_k; 2009-03-26 at 12:29.

  11. #11
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: cannot access RMS from midilet suite

    If both MIDlets are in the same JAR, all you need is:

    PHP Code:
    RecordStore rs RecordStore.openRecordStore(RECORD_STORE_NAMEtrue);
    try {
        
    // do whatever here
    finally {
        
    rs.closeRecordStore();

    Double-check the obvious things, make sure the record store names are identical in both midlets, and that the record stores are always closed after use.

    Cheers,
    Graham.

  12. #12
    Registered User
    Join Date
    Oct 2007
    Location
    Noida
    Posts
    152

    Re: cannot access RMS from midilet suite

    @ senthil

    hi again.
    But i have not written any code that will erase the recordstore.

    for opening
    Code:
     rs_choiceFCCatFVS = null;
                    rs_choiceFCCatFVS = RecordStore.openRecordStore(table_name,true,RecordStore.AUTHMODE_ANY,true);
    for writing
    Code:
    byte[] byte_FCCatFVS = "this is my string that i want to put in RMS".getBytes();
    rs_choiceFCCatFVS.addRecord(byte_FCCatFVS,0,byte_FCCatFVS.length);
    for reading in Midlet A
    Code:
    byte[] byteFCCstFVS = new byte[300];
                int len;
                len = rs_choiceFCCatFVS.getRecord(1, byteFCCstFVS, 0);
                strFCCatFVS = new String(byteFCCstFVS, 0, len);
                strFCCatFVS.trim();
    finally i am closing .. i am closing only because i thought that this might be the reason that my recordstore is not getting saved.
    its not of much use i think .

    this is the code that i am using for reading form Midlet B.
    Its pretty much the same but the recordstore is not available.
    Code:
     byte[] byte_Extraceted = new byte[300];
            
            try
            {
                rs_Main.openRecordStore(table_name,false);
                int len = rs_Main.getRecord(1,byte_Extraceted,0);
                strExtractedData = new String(byte_Extraceted,0,len);
                form.append(strExtractedData);
                form.append("after data is appended");
            }
    the above code gives me an error saying that record store not available.

    also i want to ask that is there a difference if we are simply converting a string to byte and putting that byte into the recordstore and using a ByteArray(In|Out)putStream and Data(In|Out)Stream and putting the byte thru that.

    Are these two different approaches making a difference when storing the data in RMS.
    Abhishek karmakar

    never- Never - NEVER -- !!! NEVER !!! GIVE UP

  13. #13
    Super Contributor
    Join Date
    Sep 2008
    Location
    Noida, U.P.
    Posts
    1,330

    Thumbs up Re: cannot access RMS from midilet suite

    Hi,

    Quote Originally Posted by Abhishek_karmakar View Post
    @ senthil

    hi again.
    But i have not written any code that will erase the recordstore.

    for opening
    Code:
     rs_choiceFCCatFVS = null;
                    rs_choiceFCCatFVS = RecordStore.openRecordStore(table_name,true,RecordStore.AUTHMODE_ANY,true);
    for writing
    Code:
    byte[] byte_FCCatFVS = "this is my string that i want to put in RMS".getBytes();
    rs_choiceFCCatFVS.addRecord(byte_FCCatFVS,0,byte_FCCatFVS.length);
    for reading in Midlet A
    Code:
    byte[] byteFCCstFVS = new byte[300];
                int len;
                len = rs_choiceFCCatFVS.getRecord(1, byteFCCstFVS, 0);
                strFCCatFVS = new String(byteFCCstFVS, 0, len);
                strFCCatFVS.trim();
    finally i am closing .. i am closing only because i thought that this might be the reason that my recordstore is not getting saved.
    its not of much use i think .

    this is the code that i am using for reading form Midlet B.
    Its pretty much the same but the recordstore is not available.
    Code:
     byte[] byte_Extraceted = new byte[300];
            
            try
            {
                rs_Main.openRecordStore(table_name,false);
                int len = rs_Main.getRecord(1,byte_Extraceted,0);
                strExtractedData = new String(byte_Extraceted,0,len);
                form.append(strExtractedData);
                form.append("after data is appended");
            }
    
    the above code gives me an error saying that record store not available.

    also i want to ask that is there a difference if we are simply converting a string to byte and putting that byte into the recordstore and using a ByteArray(In|Out)putStream and Data(In|Out)Stream and putting the byte thru that.

    Are these two different approaches making a difference when storing the data in RMS.
    First of all ur not closing the recordstore in Midlet A after reading and writing which is not quite good.
    Second look at ur code when ur reading the data in Midlet B. Why ur doing so when it can be done in simple way as just
    byte[] data = recordstore.getRecord(1);
    String string = new String(data);
    form.append(data);
    Also no need to set parameter false in Midlet B. What will be the result if u execute the Midlet B first with parameter false. It will throw RecordStoreNotFound Exception.
    Why r u making ur code complex. I have also tried out the same probem at my end, but it runs perfectly. here is my code

    //////// dummymidlet1/////////////
    public class dummyMidlet extends MIDlet {
    RecordStore rs = null;
    protected void startApp() throws MIDletStateChangeException {
    try {
    rs = RecordStore.openRecordStore("ABC", true);
    String str = "Hi myself jitendra agarwal";
    byte[] data = str.getBytes();
    rs.addRecord(data, 0, data.length);
    str = new String(rs.getRecord(1));
    System.out.println("string in dummy 1 is _______"+ str);
    rs.closeRecordStore();
    }
    catch (Exception ex)
    {
    ex.printStackTrace();
    }
    }

    protected void pauseApp() {

    }

    protected void destroyApp(boolean arg0) throws MIDletStateChangeException {

    }
    }
    /////////////////////////////////////////////////////////////////

    /////////////////for dummymidlet2////////////////////////////////

    public class dummy2Midlet extends MIDlet {

    RecordStore rs = null;

    protected void startApp() throws MIDletStateChangeException {
    try {
    rs = RecordStore.openRecordStore("ABC", true);
    if (rs == null)
    System.out.println("recordstore is null>>>>>>>>"+rs);
    String str = null;
    str = new String(rs.getRecord(1));
    System.out.println("string in dummy 2 = "+str);
    rs.closeRecordStore();
    } catch (Exception ex) {
    ex.printStackTrace();
    }
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }
    }
    ///////////////////////////////////////////////////////////////////////////////

    try it at ur end. Reply what will be ur result..
    thanks,
    jitu_goldie..

    KEEP TRYING..

  14. #14
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: cannot access RMS from midilet suite

    Quote Originally Posted by Abhishek_karmakar View Post
    But i have not written any code that will erase the recordstore.
    The emulator itself will delete the RMS, unless you install the midlet using the emualtor's application manager.

    Quote Originally Posted by Abhishek_karmakar View Post
    also i want to ask that is there a difference if we are simply converting a string to byte and putting that byte into the recordstore and using a ByteArray(In|Out)putStream and Data(In|Out)Stream and putting the byte thru that.

    Are these two different approaches making a difference when storing the data in RMS.
    So far as RMS, these make no difference.

    However, they are different. DataOutput.writeUTF() will always encode the characters using UTF-8, which means that all unicode characters will be safe. When you use DataInput.readUTF(), you will get back exactly the same String.

    When you use String.getBytes(), characters are converted to bytes using the platform default encoding. This might be UTF-8, but more likely it is something else (usually ISO-8859-1). ISO-8859-1 can represent only the first 256 characters from the unicode set, so this works for English, French, German, Spanish, and some other Western European languages. However, code that seems to work will suddenly stop working when your application is translated to Russian, Romanian, Czech, Greek, Arabic, Chinese, ...

    Because String.getBytes() behaves differently on different devices, and because it is not localization-safe, I strongly recommend avoiding it.

    For RMS, I recommend using DataInput/DataOutput to read and write byte arrays, because they are a simple and reliable way to encode all kinds of information into bytes, and to combine a series of fields into a single record. They are localization-safe, and perform well across different devices.

    Cheers,
    Graham.

  15. #15
    Registered User
    Join Date
    Oct 2007
    Location
    Noida
    Posts
    152

    Re: cannot access RMS from midilet suite

    hi jitu_goldie,

    protected void startApp() throws MIDletStateChangeException {
    try {
    rs = RecordStore.openRecordStore("ABC", true);
    if (rs == null)
    System.out.println("recordstore is null>>>>>>>>"+rs);
    String str = null;
    str = new String(rs.getRecord(1));
    System.out.println("string in dummy 2 = "+str);
    rs.closeRecordStore();
    } catch (Exception ex) {
    ex.printStackTrace();
    }
    }
    i tried this code but it is showing me
    1.>javax.microedition.rms.InvalidRecordIDException
    with 0 or 1



    Last edited by Abhishek_karmakar; 2009-03-26 at 14:42.
    Abhishek karmakar

    never- Never - NEVER -- !!! NEVER !!! GIVE UP

Similar Threads

  1. Replies: 8
    Last Post: 2008-07-27, 03:30
  2. RMS record sizes.
    By earamsey in forum Mobile Java General
    Replies: 1
    Last Post: 2007-10-18, 13:51
  3. N70 Access Point Selection
    By ravey72 in forum Mobile Java General
    Replies: 2
    Last Post: 2006-09-22, 20:12
  4. Midlet Suite accessing other Midlet Suites' RMS
    By je_alipio in forum Mobile Java General
    Replies: 1
    Last Post: 2004-09-14, 13:23
  5. 7210 & 7250 RMS resetting problem
    By keithmcneill in forum Mobile Java General
    Replies: 1
    Last Post: 2003-11-13, 21:04

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×