BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 11-24-2008, 09:26 AM   #1
hibbert
Thumbs Must Hurt
 
Join Date: May 2007
Location: berlin, germany
Model: 8310
PIN: N/A
Carrier: vodafone
Posts: 163
Default save my vector persistent

Please Login to Remove!

hi,
i have a vector. each item of this vector is an object of an own class (always the same calss).

now i want to save this vector and reaload it the next time my application is started.

is teher a way to do this?

thanks hibbert
__________________
My English is so bad, that makes me nobody so quickly after
Offline  
Old 11-24-2008, 09:38 AM   #2
hrbuckley
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Default

Check out the PersistentStore, and the Persistable interface.
Offline  
Old 11-28-2008, 07:03 AM   #3
hibbert
Thumbs Must Hurt
 
Join Date: May 2007
Location: berlin, germany
Model: 8310
PIN: N/A
Carrier: vodafone
Posts: 163
Default

hi, ok i have written my own class, which should save a vector.
i run my application -> load non existing data -> nothing happens -> OK
i gererate some data to save it > save the data -> OK -> quit the application
i run my application again -> load existing data -> data is shown -> OK
i turn of my blackberry (remove the batterie) -> boot it -> run my application -> load da... what? where is my data? the vector is null. what's wrong?

here is my complete class:
PHP Code:
class clsSave {
    private static 
Vector _data;
    private static 
PersistentObject store// = PersistentStore.getPersistentObject(0x444ed4bfea1c3f22L);
    
    
clsSave() { // constructor
        
if (store == nullstore PersistentStore.getPersistentObject(0x444ed4bfea1c3f22L);
        
_data = new Vector();
    }
    
    public 
void save(Vector _liste) { // gets a vaector, and should save it
        
if (store == nullstore PersistentStore.getPersistentObject(0x444ed4bfea1c3f22L);
        
synchronized(store) {
            
store.setContents(_liste);
            
store.commit();
        }
    }
    public 
Vector load() { // get the persistent data and returns a vector
        
synchronized(store) {
            
_data = (Vector)store.getContents();
        }
        return 
_data;
    }

so why is teh data los when i turn off my BB?

thanks hibbert
__________________
My English is so bad, that makes me nobody so quickly after
Offline  
Old 11-28-2008, 11:23 AM   #4
simon.hain
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Default

seems strange. did you try to actually put something into the vector? just a guess, maybe the system GCs the store because there is only an empty vector in it.
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 12-01-2008, 02:58 AM   #5
hibbert
Thumbs Must Hurt
 
Join Date: May 2007
Location: berlin, germany
Model: 8310
PIN: N/A
Carrier: vodafone
Posts: 163
Default

hi,
as i wrote in my last post, i store some data into the vector, quit my programm and restart it. then the data is loaded correctly. even if i shutdown the BB then the data is lost.

any ideas?

thanks hibbert
__________________
My English is so bad, that makes me nobody so quickly after
Offline  
Old 12-01-2008, 09:14 AM   #6
blakeburry
New Member
 
Join Date: Dec 2008
Model: 666
PIN: N/A
Carrier: T-Eufel
Posts: 4
Default

I do the same thing. As long as the battery stays charged in the device the data are there. If you remove the battery and insert it again the data is lost.

I'm looking for a solution for quite a while.

At the moment I have additional problems with commit() - it crashes most of the time but the reason for this is probably my own fault.
Offline  
Old 12-02-2008, 02:57 AM   #7
hibbert
Thumbs Must Hurt
 
Join Date: May 2007
Location: berlin, germany
Model: 8310
PIN: N/A
Carrier: vodafone
Posts: 163
Default

hi,
if i store a string array with a fixed size then the data is saved correctly, also if i remove the batterie.
maybe the problem is, that a vector can have different sizes. maybe i just have to say: dear BB, give me space for 15 elements, also when my vector has just 4 elements.

is there a way to try it this way? ^^

thanks hibbert
__________________
My English is so bad, that makes me nobody so quickly after
Offline  
Old 12-02-2008, 03:59 AM   #8
Ivanov
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
Default

try the "static way"

Code:
class clsSave {
    private static Vector _data;
    private static PersistentObject store;

    static
    {
        store= PersistentStore.getPersistentObject(0x444ed4bfea1c3f22L);
        synchronized (store)
        {
            _data= (Vector) store.getContents();
            if (_data== null)
            {
                _data= new Vector();
                store.setContents(_data);
                store.commit();
            }
        }
    }

    
    clsSave() { // constructor
    }
    
    public void save(Vector _liste) {
        _data = _liste;
        synchronized (store)
        {
            store.setContents(_data);
            store.forceCommit();
        }
    }
    public Vector load() {
        return _data;
    }
}
This should work however it might be not necessary to replace the Vector object in the store by a new one. In my application I define getter and setter for the vector's element not for the vector itself.
__________________
Blessed is the end user who expects nothing, for he/she will not be disappointed. (Franklin's Rule)
Offline  
Old 12-02-2008, 04:56 AM   #9
hibbert
Thumbs Must Hurt
 
Join Date: May 2007
Location: berlin, germany
Model: 8310
PIN: N/A
Carrier: vodafone
Posts: 163
Default

hi,
it is of no importance how i access to the vector,or? the main problem is to save it permanently.

your way returns the same result as my one.
i can restart the application an the data is loaded. but if i remove the battery then teh data is lost :(

hibbert
__________________
My English is so bad, that makes me nobody so quickly after
Offline  
Old 12-02-2008, 05:05 AM   #10
Ivanov
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
Default

try to copy all elements of _liste into _data beacuse
_data = _liste

sets only the reference to the new vector without making a deep copy

so try that:
Code:
    public void save(Vector _liste) {
        _data.removeAllElements();
        for (Enumeration e = _liste.elements(); e.hasMoreElements();)
        {
              _data.addElement(e.nextElement());
        }
        synchronized (store)
        {
            store.forceCommit();
        }
    }
__________________
Blessed is the end user who expects nothing, for he/she will not be disappointed. (Franklin's Rule)

Last edited by Ivanov; 12-02-2008 at 05:06 AM..
Offline  
Old 12-02-2008, 06:59 AM   #11
hibbert
Thumbs Must Hurt
 
Join Date: May 2007
Location: berlin, germany
Model: 8310
PIN: N/A
Carrier: vodafone
Posts: 163
Default

at the moment i have try it with this one here:
PHP Code:
public void save(Vector _liste) {
        try {
            if (
_data == null_data = new Vector();
            
this._data.removeAllElements();
            for (
Enumeration e _liste.elements(); e.hasMoreElements();){
                
_data.addElement(e.nextElement());
            }
    
            if (
store == nullstore PersistentStore.getPersistentObject(0x444ec4babc0c3f52L); 
            
synchronized (store){
                
store.setContents(_data);
                
store.commit();
            }
        } catch (
Exception ex) {System.out.println("error 0x5540: "+ex.toString());}
    } 
and i get this error:
error 0x5540: net.rim.device.api.system.NonPersistableObjectExce ption
but i don't have any idea. store and _data are not null.

hibbert
__________________
My English is so bad, that makes me nobody so quickly after
Offline  
Old 12-02-2008, 07:13 AM   #12
Ivanov
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
Default

a question in between:
what do you save in your _data vector?

if it's your own class it has to implement the Persistable interface as well.
__________________
Blessed is the end user who expects nothing, for he/she will not be disappointed. (Franklin's Rule)
Offline  
Old 12-02-2008, 08:03 AM   #13
hibbert
Thumbs Must Hurt
 
Join Date: May 2007
Location: berlin, germany
Model: 8310
PIN: N/A
Carrier: vodafone
Posts: 163
Default

hi,
each item of my _data vector is one of my own class (see first post).

how doi implement the persistable interface to my own class?

hibbert
__________________
My English is so bad, that makes me nobody so quickly after
Offline  
Old 12-02-2008, 08:22 AM   #14
Ivanov
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
Default

Code:
import net.rim.device.api.util.Persistable;

class MyPersistableClass implements Persistable
{
}
__________________
Blessed is the end user who expects nothing, for he/she will not be disappointed. (Franklin's Rule)
Offline  
Old 12-02-2008, 08:33 AM   #15
hibbert
Thumbs Must Hurt
 
Join Date: May 2007
Location: berlin, germany
Model: 8310
PIN: N/A
Carrier: vodafone
Posts: 163
Default

Quote:
Originally Posted by Ivanov View Post
Code:
import net.rim.device.api.util.Persistable;

class MyPersistableClass implements Persistable
{
}
jepp, i found it my self, was reallay an easy step ^^

i have tried this one, and i don't know what i should say....

it works

thanks alot for your help
__________________
My English is so bad, that makes me nobody so quickly after
Offline  
Old 12-03-2008, 04:58 AM   #16
blakeburry
New Member
 
Join Date: Dec 2008
Model: 666
PIN: N/A
Carrier: T-Eufel
Posts: 4
Default

Ahhh! This is the solution. If it is implemented right there are no crashes and the data is saved. Real nice from the compiler that it doesn't even warn you if you forgot the implementation...

Thanks a lot.

Thread could be closed.
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


BLACKBERRY MEAD Advertising Vinyl Banner Flag Sign Many Sizes MEDIEVAL picture

BLACKBERRY MEAD Advertising Vinyl Banner Flag Sign Many Sizes MEDIEVAL

$147.47



BLACKBERRY MEAD Advertising Vinyl Banner Flag Sign Many Sizes MEDIEVAL V2 picture

BLACKBERRY MEAD Advertising Vinyl Banner Flag Sign Many Sizes MEDIEVAL V2

$87.83



Blackberries Advertising Vinyl Banner Flag Sign Many Sizes Available USA picture

Blackberries Advertising Vinyl Banner Flag Sign Many Sizes Available USA

$174.84



FARM FRESH BLACKBERRIES CLEARANCE BANNER Advertising Vinyl Flag Sign AAA picture

FARM FRESH BLACKBERRIES CLEARANCE BANNER Advertising Vinyl Flag Sign AAA

$174.84



Blackberry Advertising Banner Vinyl Mesh Sign Fruit Vegetable Berry Farm Fresh picture

Blackberry Advertising Banner Vinyl Mesh Sign Fruit Vegetable Berry Farm Fresh

$219.95



BLACKBERRY MEAD Advertising Vinyl Banner Flag Sign Many Sizes MEDIEVAL picture

BLACKBERRY MEAD Advertising Vinyl Banner Flag Sign Many Sizes MEDIEVAL

$125.58







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.