Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
JosuB
Posts: 9
Registered: ‎09-21-2009
My Device: Not Specified
Accepted Solution

Trouble with persistence

Hi everybody,

 

This is my first post so excuse me in case I make any mistake. I am a newbie in developing BlackBerry apps and I am having serious trouble with persistence. Indeed it is not working at all. I am using Eclipse IDE with BB plugin, BB JDE version 4.7 and 8110 simulator.

 

As nothing was working at all with persistence I wrote this simple code that executes at the begining of the app. First time PersistentObject content should be null and filled with a new "Posicion". Next time I run the app the persistentObject content should contain that "Posicion", shouldn`t it?

 

Here's the code for the the trouble, What am I doing wrong??

 

 

private void prueba() { Posicion pos; PersistentObject persistentPosicion = PersistentStore.getPersistentObject(Posicion.class.hashCode()); synchronized (persistentPosicion) { if (persistentPosicion.getContents() == null) { pos = new Posicion(-1.45878, 42.3657489, 12, new Date().getTime()); persistentPosicion.setContents(pos); persistentPosicion.commit(); } else { pos = (Posicion)persistentPosicion.getContents(); } } }

 

 And the "Posicion" class:

 

 

public class Posicion implements Persistable{ private double longitud; private double latitud; private double velocidad; private Long fecha; public Posicion() { longitud = 400; latitud = 400; velocidad = 0; fecha = new Long(new Date().getTime()); } public Posicion(double longi, double lat, double vel, long fech) { longitud = longi; latitud = lat; velocidad = vel; fecha = new Long(fech); } public Long getFecha() { return fecha; } public double getLatitud() { return latitud; } public double getLongitud() { return longitud; } public double getVelocidad() { return velocidad; } public void setFecha(Long fecha) { this.fecha = fecha; } public void setLatitud(double latitud) { this.latitud = latitud; } public void setLongitud(double longitud) { this.longitud = longitud; } public void setVelocidad(double velocidad) { this.velocidad = velocidad; }}

 

 I will appreciate any kind of help. Feel free to ask anything you consider neccessary to solve my problem. I'm really stuck with this.

 

Thanks in advance.

 

JosuB 

 

 

 

 

Please use plain text.
Developer
simon_hain
Posts: 16,004
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Trouble with persistence

in the jde there is a string to long converter. try to use a generated long for the store instead of the hashcode.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
kumaresan
Posts: 183
Registered: ‎12-17-2008
My Device: 8320

Re: Trouble with persistence

 

Try code like this. 

 

 private static Vector addresses= new Vector();
 private static PersistentObject store;

 

        long key=0xfe6528d5d4ad62d1L;
        store = PersistentStore.getPersistentObject(key);
       
        Vector indata = (Vector)store.getContents();
        if(indata==null) {
            indata=new Vector();
        }
             indata.addElement(*****);
       
        synchronized (store)
        {
            store.setContents(indata);
            store.commit();
        }           

kums

******************************

Press kudos which the post help you
Please mark posts as solved if you got a solution
Please use plain text.
New Developer
JosuB
Posts: 9
Registered: ‎09-21-2009
My Device: Not Specified

Re: Trouble with persistence

Thank you both it happened to be something wrong with the keys I used to identify the persistentObject in the persistentstore. i really appreciate your help.

 

JosuB 

Please use plain text.