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
mudit_sri
Posts: 9
Registered: ‎03-04-2013
My Device: 9320
Accepted Solution

How to resolve NonPersistableObjectException

I have a simple method written as:

 

public static void set(long uniqueId, String value) {
        store = PersistentStore.getPersistentObject(uniqueId);
        synchronized (store) {
            store.setContents(value);
            store.commit();
        }
    }

 

This method works very well for the first time, but second time it fails with NonPersistableObjectException.

 

Point to note is that, same unique id i am updating with same value.

Please use plain text.
Developer
simon_hain
Posts: 16,215
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: How to resolve NonPersistableObjectException

are you sure you are only storing strings?
----------------------------------------------------------
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
peter_strange
Posts: 19,609
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to resolve NonPersistableObjectException

Just wondered if persisting a null object would give this error.

 

Can I also suggest that instead of using up loads of unqiue ids with just a String, persist a collection in the same persistent id, and use a HashTale to extract the value you want.  I like IntHashTable for this sort of thing. 

Please use plain text.
New Developer
mudit_sri
Posts: 9
Registered: ‎03-04-2013
My Device: 9320

Re: How to resolve NonPersistableObjectException

Yeah.

I placed a log statement before persisting the value, and the value is not null but some string value

 

Can this be device issue ? Not sure just guessing.

Please use plain text.
New Developer
mudit_sri
Posts: 9
Registered: ‎03-04-2013
My Device: 9320

Re: How to resolve NonPersistableObjectException

@Peter: If i am not getting any solution then for sure i will change my implementation. You are suggesting to use Collection, what if i store my own object that implements Persistence. Won't this be a better idea ?
Please use plain text.
Developer
peter_strange
Posts: 19,609
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to resolve NonPersistableObjectException

Have you created an Object that extends String that you are storing?  If so, you will have to implement Persistable in that Object. 

 

Your own Object is a good idea also.  But there is an issue with Persistent Objects when you upgrade them.  Say you create an Object like the following:

 

class MyPersistentObject extends Persistable {

String _string1 = null;

String _string2 = null;

....

String getString1() {

return _string1;

}

...

}

 

Now for V2, you want to add another String, so you have

 

class MyPersistentObject extends Persistable {

String _string1 = null;

String _string2 = null;

String _string3 = null;

....

String getString3() {

return _string3;

}

...

}

 

Now because you have changed the structure of this persisted object, you have in fact made the persisted class on the device incompatible with your upgrade.  To install, users will have to delete the old app, loosing this stored data.

 

However if you did this for start with:

 

class myPersistedObject extends IntHashTable implements Persistable {

...

String getString1() {

return this.get(1);

}

....

}

 

Then to add another String you just add the get method:

 

class myPersistedObject extends IntHashTable implements Persistable {

...

String getString3() {

return this.get(3);

}

....

}

 

The structure does not change and this is compatible.

 

The above code is NOT correct, hopefully you get the idea. 

 

So create your own class, but extend a Collection object and you get the flexibility and upgradeability. 

 

Hope this makes sense. 

Please use plain text.
New Developer
mudit_sri
Posts: 9
Registered: ‎03-04-2013
My Device: 9320

Re: How to resolve NonPersistableObjectException

@Peter: I was thinking to implement as you mentioned in example1, but yeah its really great that before hand you pointed out the problem that can occur :smileyhappy:

You mentioned, if we delete the app, it will delete the persistent data as well. I dont agree with this. I have an app, persistent some value. I uninstalled the app and reinstalled new upgraded app, still i can view my previous data.
Please use plain text.
Developer
peter_strange
Posts: 19,609
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to resolve NonPersistableObjectException

You said "really great that before hand you pointed out the problem that can"

Been there, done that, got caught, don't want to do it again......

 

You said "I dont agree with this. I have an app, persistent some value. I uninstalled the app and reinstalled new upgraded app, still i can view my previous data."

In this case, you will have used only standard objects, like Strings.

 

If you create your own persisted Object, then deleting the application will delete the persisted object.  But if you upgrade (without deleting) an application with its own persisted class, the persisted data will remain (assuming it is compatible). 

 

Please use plain text.