Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User andybeeeeee's Avatar
    Join Date
    Mar 2006
    Location
    Somewhere, England
    Posts
    15
    Hi

    I'm creating an application that gets a users position from a gps and uses it to perform different tasks. The way i was going to perform these tasks was to create a midlet suite with each of the tasks as a different MIDlet and pass the data from the gps, which is retrieved in its own midlet, to the others.

    What i need to know is, is this possible? I've heard that you can use a record store and the rms api to have common data between different midlets in a suite, but would this work and is it a bit of an overkill? is there an easier way of doing this that i'm not seeing?

    thanks
    Andy

  2. #2
    Registered User juarezjunior's Avatar
    Join Date
    Dec 2005
    Location
    Brazil
    Posts
    1,883
    Hi Andy,

    I don't think sharing record stores is an overkill. This capability was introduced in MIDP 2.0 and it's useful.

    BR

  3. #3
    Registered User andybeeeeee's Avatar
    Join Date
    Mar 2006
    Location
    Somewhere, England
    Posts
    15
    thanks alot for the answer! i'll try this, but i have a feeling i'll be abck with more questions....

  4. #4
    Registered User andybeeeeee's Avatar
    Join Date
    Mar 2006
    Location
    Somewhere, England
    Posts
    15
    I found an example class for creating my record store and i implemented it in this class:
    Code:
    import javax.microedition.rms.*;
    import java.util.Enumeration;
    import java.util.Vector;
    import java.io.*;
    
    public class PosDB {
       public RecordStore recordStore = null;
       public PosDB() {}
    
       // Open a record store with the given name
       public PosDB(String fileName) {
          try {
            recordStore = RecordStore.openRecordStore(fileName, true);
          } catch(RecordStoreException rse) {
            rse.printStackTrace();
          }
       }
    
       // Close the record store
       public void close()
    	    throws RecordStoreNotOpenException,
                           RecordStoreException {
            if (recordStore.getNumRecords() == 0) {
                String fileName =
                               recordStore.getName();
                recordStore.closeRecordStore();
                recordStore.deleteRecordStore(
                                          fileName);
            } else {
                recordStore.closeRecordStore();
            }
        }
    
       // Add a new record (position)
       // to the record store
       public synchronized void addNewPos(String record) {
         
        byte[] rec = record.getBytes();
    
        try
        {
          recordStore.addRecord(rec, 0, rec.length);
        }
        catch (Exception e)
        {
          System.out.println(e);
          e.printStackTrace();
        }
      }
    
    
        // Enumerate through the records.
        public synchronized RecordEnumeration enumerate() throws RecordStoreNotOpenException {
           return recordStore.enumerateRecords(null, null, false);
        }
        
        public synchronized byte[] getPos(int number){
          byte[] recData = new byte[2];
          try
          {
            if (recordStore.getRecordSize(number) > recData.length)
              recData = new byte[recordStore.getRecordSize(number)];
            recData = recordStore.getRecord(number);
                          
          }
          catch (Exception e)
          {
            System.out.println(e);
            e.printStackTrace();
          }
          return recData;
        }
    }
    now i think this should be correct for the basic functions of adding to the database etc, so in another class i write

    Code:
    public void addToDatabase(){
          try{
           db = new PosDB("positions");
         } catch (Exception e){}
         try {
          db.addNewPos(splitData[2]+splitData[3]);
        }catch(Exception e) {}
         try{
           db.addNewPos(splitData[4]+splitData[5]);
         }catch(Exception e) { }
         try {
            db.close();
          } catch(Exception e) {}
        return;
        }
    this should be right yes?

    anyway, i then try to output the contents of records 1 and 2 to the screen ina test midlet that's part of my midlet suite:
    Code:
    public void startApp() throws MIDletStateChangeException{
        boolean b;
        try{
            db = new PosDB("positions");
          } catch (Exception e){}
          positiona = db.getPos(1);
          for(int i=0; i<positiona.length; i++){
            position1+=( char )positiona[ i ];
          }
    
          positionb = db.getPos(2);
          for(int j=0; j<positionb.length; j++){
           position2+=( char )positionb[ j ];
         }
          display = Display.getDisplay(this);
          display.setCurrent(form);
          form.addCommand(exitCommand);
          
          form.append("position 1:");
          form.append(position1 + "\n");
          form.append("position 2:");
          form.append(position2 + "\n");
          try{
            db.close();
          }
          catch(Exception e){
            System.out.println(e);
          }
    but all i get coming out is null. for the life of me i can't figure out why this is happening, i'd normally put in some println statements to make sure everything's being called and data is being save etc, but i cant do that on a moble device and i dont think i can use bluetooth on the emulator... this is my first mobile application and it's abit tough!

    can anyone see where i'm going wrong?
    sorry for the mammouth post!!!
    Andy

Similar Threads

  1. suckho, i have encontered the same problems. Could you tell me how you resolved it?
    By dicson_hu in forum Symbian Networking & Messaging (Closed)
    Replies: 4
    Last Post: 2005-12-09, 10:56
  2. GPRS connection problems on 6600..
    By suckho in forum Symbian Networking & Messaging (Closed)
    Replies: 10
    Last Post: 2005-12-02, 14:00
  3. 6600 gprs 发送大量rtp延时问题
    By dicson_hu in forum Symbian
    Replies: 9
    Last Post: 2005-11-04, 02:12
  4. Nokia 6600 Socket Server send delay Problem
    By dicson_hu in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2005-10-31, 07:37
  5. Replies: 2
    Last Post: 2004-09-15, 22:47

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved