×

Discussion Board

Results 1 to 15 of 15
  1. #1
    Regular Contributor
    Join Date
    Oct 2007
    Location
    PUNE,INDIA
    Posts
    52

    Unhappy RMS in Nokia 2760

    I am creating a J2ME application on the Nokia 2760 . Essentialy , the app is required to read GPS data from a Bluetooth device and upload via GPRS connection when a specific condition is satisfied . However, the application is not ceating a .db file , instead it is creating a .rms file. the data is saved properly in .rms file but while reading this file the midlet always throws null pointer exception . Can anyone help out ? ( The JAR file in the PC is copied into the 2760 using a Bluetooth connection since 2760 does not have cable connectivity ) .

  2. #2
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: RMS in Nokia 2760

    Hi Rama1962,

    when using RecordStores in Java ME you do not need to know where/how data files are stored, since all file writing/reading operations are done via RecordStore methods, and not directly reading those files.

    About your Exception, you should post relevant code portions, so it'll be possible to sort out its cause.

    Pit

  3. #3
    Regular Contributor
    Join Date
    Oct 2007
    Location
    PUNE,INDIA
    Posts
    52

    Re: RMS in Nokia 2760

    Thanks!

    Basically i want to save the data i get from BT GPS like this:
    00154B1156F1|$GPRMC,105105.000,A,1828.6366,N,07354.1493,E,1.92,0.77,180908,,,A*60
    00154B1156F1|$GPRMC,105304.000,A,1828.6506,N,07354.1313,E,0.00,336.89,180908,,,A*61
    The rms file looks like this:
    midp-rms Wê…Mž‘³‚KàÎ¥
    ?ÆÓ´Ê ¸ u”Ò H ( p S Q00154B1156F1|$GPRMC,105105.000,A,1828.6366,N,07354.1493,E,1.92,0.77,180908,,,A*60 H p U S00154B1156F1|$GPRMC,105304.000,A,1828.6506,N,07354.1313,E,0.00,336.89,180908,,,A*61
    When i read this file in midlet also the data i save is appended by some charecters like Q,S,P,etc and even with junk or unprintable characters.

    to overcome this i used trim() before i add record but result is the same.

    Please help me out
    Thanks in advance.
    Last edited by Rama1962; 2008-09-18 at 12:39.

  4. #4
    Regular Contributor
    Join Date
    Oct 2007
    Location
    PUNE,INDIA
    Posts
    52

    Re: RMS in Nokia 2760

    Also after reading i need to delete the record one by one.
    Can any kind soul help me in this as well

    Thanks in advance.

  5. #5
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: RMS in Nokia 2760

    Hi Rama1962,

    how do you read the saved data from your RecordStore? RMS file content is not meaningful for your MIDlet needs, since all you need to do is to use RecordStore methods to get the data you need.

    You could try posting the code you use to save and read your data, so it would be possible to check for possible issues.

    Also, to delete records from a a RecordStore, you should use the deleteRecord() method, specifying the ID of the record you want to remove.

    Pit

  6. #6
    Registered User
    Join Date
    Sep 2007
    Location
    Mumbai, India
    Posts
    54

    Re: RMS in Nokia 2760

    Hi,
    Jappit is right. You cannot read the rms files directly. There are certain methods to create and read record stores like:

    RecordStore rms = null;
    rms = RecordStore.openRecordStore("name", true);


    To write a string data in the record store:

    public void write(String s1) {
    try {
    byte b[] = s1.getBytes();
    rms.addRecord(b, 0, b.length);

    } catch (Exception e) {
    System.out.println(e);
    }
    }

    Now, this data gets added to the record store at record id 1, if its the first time you are writing anything to the rms.

    So, in case you need to access the string, your code goes like:-

    public String read(int recid) {
    try {

    byte b[] = rms.getRecord(recid);
    String s1 = new String(b);

    return s1;
    } catch (Exception e) {
    e.printStackTrace();
    }
    return "";
    }

    where in you pass recid as 1.

    Similarly, you can use the rms to store any type of data, and subsequently read the same.

    Regards,
    Sanket

  7. #7
    Regular Contributor
    Join Date
    Oct 2007
    Location
    PUNE,INDIA
    Posts
    52

    Re: RMS in Nokia 2760

    Thanks for your comments.
    My code to write in rms:
    Code:
    public synchronized void addNewRecord(String record) {
    	ByteArrayOutputStream baos = new 
    		ByteArrayOutputStream();
    	DataOutputStream outputStream = new 
    		DataOutputStream(baos);
    	try {
    	    outputStream.writeUTF(record);
    	}
    	catch (IOException ioe) {
    	    System.out.println(ioe);
    	    ioe.printStackTrace();
    	}
    	byte[] b = baos.toByteArray();
    	try {
    	    recordStore.addRecord(b,0, b.length);
    	}
    	catch (RecordStoreException rse) {
    	    System.out.println(rse);
    	    rse.printStackTrace();
    	}
        }
    and to read
    Code:
    StringBuffer Data = null;
           try {
         RecordEnumeration enum =db.enumerate();                     
          Data = new StringBuffer();
           while(enum.hasNextElement()) {
            String RmcData = new String(enum.nextRecord());
             Data.append(RmcData.trim());
     }
           } catch(Exception ex) {}
    
    public synchronized RecordEnumeration enumerate() 
      throws RecordStoreNotOpenException {
         return recordStore.enumerateRecords(null, null, false);
        }
    Code:
    private void AddToRMS(){
    try {
            db = new GprmcDB("Props");
          } catch(Exception e) {}
              try {
    		String pr ="|"+ Myid + MyGprmc;
                    db.addNewRecord(pr.trim());
                } 
                 catch(NumberFormatException se) {
                }
        }
    Also when i call AddToRMS() on a command button data is saved in rms file but when i call from
    public void run()
    the data is not saved at all.
    Also what surprises is file extension is not .db but .rms
    Am i doing some thing wrong?

  8. #8
    Registered User
    Join Date
    Sep 2007
    Location
    Bangalore
    Posts
    868

    Re: RMS in Nokia 2760

    Hi,
    Incase of writing the data in to rms you are using writeUTF in to DataOutPutstream And after you are taking that byte array from the DataOutputstream and writing. But in case of reading you are not doing in the same way. You have to read your data to DataInputStream and read that as readUTF() then only you will get the proper data

  9. #9
    Regular Contributor
    Join Date
    Oct 2007
    Location
    PUNE,INDIA
    Posts
    52

    Re: RMS in Nokia 2760

    1}When i call AddToRMS() on a command button data is saved in rms file but when i call from
    public void run()
    the data is not saved at all.
    2}Also what surprises is file extension is not .db but .rms
    Am i doing some thing wrong?
    can any kind soul please help me in this.
    I tried to run the app on sony erricson but it throwed an exception while creating rms.

    Thanks in advance

  10. #10
    Regular Contributor
    Join Date
    Oct 2007
    Location
    PUNE,INDIA
    Posts
    52

    Thumbs down Re: RMS in Nokia 2760

    Quote Originally Posted by sanket2612 View Post
    RecordStore rms = null;
    rms = RecordStore.openRecordStore("name", true);
    public String read(int recid) {
    try {
    byte b[] = rms.getRecord(recid);
    String s1 = new String(b);
    return s1;
    } catch (Exception e) {
    e.printStackTrace();
    }
    return "";
    }
    My problem is i dont know the no of records in rms and the recid.
    Is there a way so that i can know no of records in rms. i want to read all the data in rms file- 3 records at a time and delete them - or at the end delete the rms itself.

    Thanks in advance

  11. #11
    Registered User
    Join Date
    Sep 2007
    Location
    Mumbai, India
    Posts
    54

    Re: RMS in Nokia 2760

    Hi,
    rms.getNumRecords() will give you the size of the rms, after which you can use a for loop, and get your rms data. Having said that, it is a good practice to keep a track of the data that you enter in the rms, which would be useful for you while reading the same. The recid is updated as an when you add data to the rms.
    Its 1 for the first entry, 2 for the second and so on.
    Another option is to create multiple record stores with different names to store a set of varied data.
    For an example, use can use a record store name like - appImages for storing image data, similarly, -appMisc, for storing a table of String, integers and images as single row. So, while fetching the data, if you need to retrieve the data from appImages, you can use the methods for retrieving image data. Again, in case of appMisc, you will need to use the appropriate methods to get a row of data. Hope this helps !!
    Regards,
    Sanket

  12. #12
    Regular Contributor
    Join Date
    Oct 2007
    Location
    PUNE,INDIA
    Posts
    52

    Re: RMS in Nokia 2760

    The problem i am facing is like this:
    I want to take no of records in rms that i get from rms.getNumRecords() in function GprmcRecord(). Now i want to loop from 1 to NumOfRec and one by one upload the records.
    But the for loop i wrote is not displaying records one by one. instead it continues to the end and displays only last record.
    I tried sleeping the thread for 1-2 sec but it doesnt display records from 1 to NumOfRec-1.

    Code:
    if (cmd == cmdRead) {
    	int NumOfRec=1;
    	String outppp="";
    	int r = 1;
    	try{
    		NumOfRec=GprmcRecord();
               }
    	catch(Exception ex) {}
    		
    	for (int r = 1; r <= NumOfRec; r++)
    	{
    		String Read=read(r);
                     //Upload(Read);
    		display(new Alert("Record: "+Read));
    	}
    
    public int GprmcRecord()
    	throws RecordStoreNotOpenException {
    	return rms.getNumRecords();
    	}
    
    
    
    public String read(int recid) {
    try {
    
    byte b[] = rms.getRecord(recid);
    String s1 = new String(b);
    
    return s1;
    } catch (Exception e) {
    e.printStackTrace();
    }
    
    return "";
    }
    Please help on how to read individual records. also if i delete all records say with recid=10. next time i add data will it have recid 1 or 11?

    Thanks in advance

  13. #13
    Regular Contributor
    Join Date
    Oct 2007
    Location
    PUNE,INDIA
    Posts
    52

    Re: RMS in Nokia 2760

    1)
    Code:
    NumOfRec=rms.getNumRecords();
    for (int i = 1; i <= NumOfRec; i++){
    	mainForm.setTicker(new Ticker("Deleting"));
    try{
    rms.deleteRecord(i); 
    }
    catch(Exception ex) {
    	display(new Alert("Record Not Deleted "));
    Instead of giving individual recid can i delete all entries in rms?
    2)
    Code:
    rms.getNumRecords();
    Along with getting no of records can i get their record id?
    3)
    Code:
    //if (rms.getNumRecords() == 0) {
                String fileName =rms.getName();
                rms.closeRecordStore();
                rms.deleteRecordStore(fileName);
    //}
    If there are records in RecordStore can we delete the RecordStore?if i try doing this it throws exception.Any workaround for this?
    Thanks in advance.
    Last edited by Rama1962; 2008-10-01 at 08:19.

  14. #14
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: RMS in Nokia 2760

    Hi Rama1962,

    about your questions:

    1) only way to delete all records at once is to delete (and recreate) the RecordStore itself. Otherwise, you have to delete records one by one.

    2) to get records IDs you should loop the records themselves (e.g.: by using enumerateRecords() method) and call getNextRecordID() for each of them. Also here, there is no a method to get all record IDs at once.

    3) Sure, you can delete your RecordStore even if it contains any records. Which kind of Exception are you getting in your code?

    Pit

  15. #15
    Regular Contributor
    Join Date
    Oct 2007
    Location
    PUNE,INDIA
    Posts
    52

    Re: RMS in Nokia 2760

    Code:
    /*	int NumOfRec=0;				
    	try{
    	NumOfRec=GprmcRecord();
    	}
    	catch(Exception ex) {
    	display(new Alert("RecordStore Not Open "));}
    	for (int rr = 1; rr <= NumOfRec; rr++)
    	{
    	mainForm.setTicker(new Ticker("Deleting"));
    	try{
    	rms.deleteRecord(rr); 
                }
    	catch(Exception ex) {
    	display(new Alert("Record Not Deleted "));
          }	}*/
    
    	try{
    	Closerms();
    	mainForm.setTicker(new Ticker("RSD"));
    	}
    	catch(Exception ex){
    	//mainForm.setTicker(new Ticker("RSND"+ex));
    	display(new Alert("RecordStore Not Deleted "));
    	}
    ******************
    public void Closerms() 
    	    throws RecordStoreNotOpenException,
                           RecordStoreException {
    
    //if (rms.getNumRecords() == 0) {
                String fileName =rms.getName();
                rms.closeRecordStore();
                rms.deleteRecordStore(fileName);
    //}
    
     }
    function GprmcRecord() gives no of records in rms.
    if i delete the records and then try to delete the recordstore it sometimes deletes.sometimes rms.deleteRecord(rr);doesnt delete all records one or two records are not deleted.
    if i try deleting the rms before deleting records it doesnt delete rms.i tried to catch exception but i couldnt get; but with display(new Alert("RecordStore Not Deleted ")); it always flashes this alert.
    Can a kind soul help me. i want to delete the recordstore and then create it.

Posting Permissions

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