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
Developer
Posts: 144
Registered: ‎03-15-2011
My Device: blackberry smart phone
My Carrier: Airtel
Accepted Solution

getting NonPersistableObjectException when try to persisit facebook object

Hello all is there a way we can persist the facebook object in our application. I want, that only once a user can login on facebook, and we want that user should persist through out the application. How can we achieve this any idea ??? When i tried to persist the user using vector it dont persisted it was giving me badpersistent object exception 525 error. When i tried to persist the facebook object i got  NonPersistableObjectException. I am using os version 5.0. i have to post on wall from the background process . So for that i want that user object. please guys help me out. 

Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: getting NonPersistableObjectException when try to persisit facebook object

to persist an object this class and all used classes must implement persistable, also all classes stored in vector or similar.
to avoid this you can write your own persistance bean and copy the relevant data.
----------------------------------------------------------
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
Developer
Posts: 144
Registered: ‎03-15-2011
My Device: blackberry smart phone
My Carrier: Airtel

Re: getting NonPersistableObjectException when try to persisit facebook object

@simon_hain i have used vector and i was adding the user in the vector. But User class doesnt implement persisitable so i stuck at that. And what do you mean by writing your own persisitance bean in this scenario. How can i use this can you elaborate it. Thanks for the reply.
Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: getting NonPersistableObjectException when try to persisit facebook object

a bean class is a data storage class with all attributes you need. just add "implements persistable" to make it persistable, and use only classes that are persistable, see the list of implementing classes at http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/util/Persistable.html
----------------------------------------------------------
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
Developer
Posts: 144
Registered: ‎03-15-2011
My Device: blackberry smart phone
My Carrier: Airtel

Re: getting NonPersistableObjectException when try to persisit facebook object

so that means i cant use User to persisit in a vector.
Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: getting NonPersistableObjectException when try to persisit facebook object

yes. unless you implement persistable in the user class (and all used subclasses) - i don't have the code here, but it seems unlikely to be trivial, better use a bean class.
----------------------------------------------------------
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
Developer
Posts: 144
Registered: ‎03-15-2011
My Device: blackberry smart phone
My Carrier: Airtel

Re: getting NonPersistableObjectException when try to persisit facebook object

This User class is from Facebook Api. import com.blackberry.facebook.inf.User. And i want to persist this user. how can i go about this.
Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: getting NonPersistableObjectException when try to persisit facebook object

use getXXX to retrieve the relevant data and store them in your own class.
when retrieving the data you create a new user object and use setXXX to fill it with the stored data.
----------------------------------------------------------
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
Developer
Posts: 144
Registered: ‎03-15-2011
My Device: blackberry smart phone
My Carrier: Airtel

Re: getting NonPersistableObjectException when try to persisit facebook object

Okkk will try that. Thanks for the help . I will try it now. If will get any problem will ask here. Thanks. Smiley Happy
Highlighted
Developer
Posts: 144
Registered: ‎03-15-2011
My Device: blackberry smart phone
My Carrier: Airtel

Re: getting NonPersistableObjectException when try to persisit facebook object

@simon_hain

 

Here how i have implemented that but getting the same exception.

 

public class SaveFacebookUserInformationVector extends Vector implements Persistable {

}

 

 

and here i am storing the data in persisitent storage

 

public class VectorUserFacebook {
	
	static long STOREFACEBOOKID = 0x90d87f1e5a98bbf0L;
	static PersistentObject storeFaceBookUser;
	
	
	static {
		storeFaceBookUser = PersistentStore.getPersistentObject(STOREFACEBOOKID);
	}
	
	public static void addUserData (SaveFacebookUserInformationVector saveFacebookUserInformationVector) {
		SaveFacebookUserInformationVector setting = retrieveUserData();
		for (int i =0; i < saveFacebookUserInformationVector.size(); i++) {
			setting.addElement(saveFacebookUserInformationVector.elementAt(i));
			System.out.println("Element Added ");
		}
		synchronized (storeFaceBookUser) {
			storeFaceBookUser.setContents(setting);
			storeFaceBookUser.commit();
		}
	}
	
	public static SaveFacebookUserInformationVector retrieveUserData () {
		
		if(storeFaceBookUser == null) {
			
			return null;
			
		}
		synchronized (storeFaceBookUser) {
			if (storeFaceBookUser.getContents() == null) {
				storeFaceBookUser.setContents(new SaveFacebookUserInformationVector());
				PersistentObject.commit(storeFaceBookUser);
			}
			return (SaveFacebookUserInformationVector) storeFaceBookUser.getContents();
		}
	}

}

 and using it like this way

 

user = facebook.getCurrentUser();
Vector vector = new Vector();
				SaveFacebookUserInformationVector saveUser = new SaveFacebookUserInformationVector();
				vector.addElement(user);
				saveUser.addElement(vector);
				VectorUserFacebook.addUserData(saveUser);