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
Aarthi
Posts: 10
Registered: ‎12-04-2008
My Device: Not Specified

NonPersistableObjectException

this class implements Persistable

 

public static boolean addMenuPage(int menuName, Hashtable screenData, int screenNo) {
        System.out.println("in addMenuPage/**********************************/");
        try {
            Object obj = menuIntHashtable.get(menuName);
            if (obj != null) {
                IntHashtable table = (IntHashtable) obj;
                table.put(screenNo, screenData);
                menuIntHashtable.put(menuName, table);
                persistentObject.commit();//forceCommit();

                table = null;
                return true;
            } else {
                return false;
            }
        } catch (Exception ex) {
            System.out.println("in DataStore - addMenuPage" + ex);
            return false;
        }
    }

 

when I exceute, it gives an Pagenet.rim.device.api.system.NonPersistableObjectException

 

how do I solve this.........

Please use plain text.
Developer
BBDeveloper
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: NonPersistableObjectException

Does this class consists any other Objects which are not Persitable.

Use Search. "Accept Solution" If the problem is resolved.
Please use plain text.
Developer
Posts: 432
Registered: ‎02-23-2009
My Device: Not Specified

Re: NonPersistableObjectException

Hi Aarthi,

 

NonPersistableObjectException thrown when we attempts to persist an object that doesn't implement the Peristable interface, or when the object being persisted contains a reference to a non-persistable object. 

 

 


Press the kudos button to thank the user who helped you.

If your problem was get solved then please mark the thread as "Accepted solution".

 

 

Deepesh Gupta
Please use plain text.
New Developer
Aarthi
Posts: 10
Registered: ‎12-04-2008
My Device: Not Specified

Re: NonPersistableObjectException

package com.mobilereflex.store;

import java.util.Hashtable;
import net.rim.device.api.system.PersistentObject;
import net.rim.device.api.system.PersistentStore;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.util.IntHashtable;
import net.rim.device.api.util.Persistable;

public class UIStore implements Persistable {

    private static IntHashtable menuIntHashtable;
    private static PersistentObject persistentObject;   

    public UIStore() {
    }

    public static void initDataStore(String keyCode, long dataID) {       
        persistentObject = PersistentStore.getPersistentObject(dataID);
        synchronized (persistentObject) {
            try {
               
                menuIntHashtable = (IntHashtable) persistentObject.getContents();
                if (menuIntHashtable == null) {
                    menuIntHashtable = new IntHashtable();                   
                    persistentObject.setContents(menuIntHashtable);
                    persistentObject.commit();
                } else {
                }

            } catch (Exception ex) {
                System.out.println("in UIStore - initDataStore" + ex);

            }
        }
    }
   
    public static boolean destroyDataStore(String keyCode, long dataID) {
       
        boolean cleaned = false;
        persistentObject = PersistentStore.getPersistentObject(dataID);
        synchronized (persistentObject) {
            try {
              
                Object obj = persistentObject.getContents();
                if (obj != null) {
                                        menuIntHashtable = (IntHashtable) obj;
                    PersistentStore.destroyPersistentObject(dataID);
                    menuIntHashtable.clear();
                    persistentObject.commit();
                    cleaned = true;                   

                }
                cleaned = true;

            } catch (Exception ex) {
                System.out.println("in UIStore - destroyDataStore" + ex);
            }
        }
        return cleaned;
    }

  
    public static void addMenuTable(int menuName) {
       
        try {
            if (!menuIntHashtable.containsKey(menuName)) {
                menuIntHashtable.put(menuName, new IntHashtable());
                persistentObject.commit();
            } else {
            }
        } catch (Exception ex) {
            System.out.println("in DataStore - addMenuTable" + ex);
        }
    }

   
    public static void setMenuTable(int menuName) {
       
        try {
            if (menuIntHashtable.containsKey(menuName)) {
                menuIntHashtable.put(menuName, new IntHashtable());
                persistentObject.commit();
            } else {
            }
        } catch (Exception ex) {
            System.out.println("in DataStore - setMenuTable" + ex);
        }
    }

   
    public static boolean addMenuPage(int menuName, Hashtable screenData, int screenNo) {
       
        try {
            Object obj = menuIntHashtable.get(menuName);
            if (obj != null) {
                IntHashtable table = (IntHashtable) obj;
                table.put(screenNo, screenData);
                menuIntHashtable.put(menuName, table);
                persistentObject.commit();
                table = null;
                return true;
            } else {
                return false;
            }
        } catch (Exception ex) {
            System.out.println("in DataStore - addMenuPage" + ex);
            return false;
        }
    }

    public static boolean setMenuPage(int menuName, Hashtable screenData, int screenNo) {
       
        try {
           
            Object obj = menuIntHashtable.get(menuName);
            if (obj != null) {
                IntHashtable table = (IntHashtable) obj;
                table.put(screenNo, screenData);
                menuIntHashtable.put(menuName, table);
                persistentObject.commit();
                table = null;
              
                return true;
            } else {
               
                return false;
            }

        } catch (Exception ex) {
            System.out.println("in DataStore - setMenuPage" + ex);
            return false;
        }
    }

  
    public static Hashtable getMenuPage(int menuName, int screenNo) {
       
        try {
           
            Hashtable screenData = null;
            Object obj = menuIntHashtable.get(menuName);
            if (obj != null) {
                IntHashtable table = (IntHashtable) obj;
                if (table.containsKey(screenNo)) {
                    screenData = (Hashtable) table.get(screenNo);
                }
                return screenData;
            } else {
                System.out.println("getMenuPage-" + menuName + "-" + screenNo + "= This page not found");
                return null;
            }
        } catch (Exception ex) {
            System.out.println("in DataStore - getMenuPage" + ex);
            return null;
        }
    }
}

 

And the execution partis as follows:

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

 

public class WFEngine extends UiApplication {

    public static long MY_DATA_ID = 0x9986dae325433beaL;
    public static final String KEY_CODE = "1473968714";
    public String[] screenNames = {"LoginScreen"};
    public int screenNos[] = {1};
   
    public WFEngine() {
       
       

        String xmlFormsrc="s.xml";

Stack dataStack = UIFactory.createForm(xmlFormSrc);      
        MainScreen ms =UIForm.createForm(dataStack);
        Hashtable screenHtbl = new Hashtable();
        screenHtbl.put(screenNames[0], ms);
        UIStore.initDataStore(KEY_CODE, MY_DATA_ID);
        UIStore.addMenuTable(1);
        boolean saveFlag = UIStore.addMenuPage(1, screenHtbl, screenNos[0]);
        System.out.println("save Flag.........."+saveFlag);
       
        Hashtable ht = UIStore.getMenuPage(1, screenNos[0]); 
        MainScreen localMainScreen = (MainScreen) ht.get(screenNames[0]);
      
        pushScreen(localMainScreen);        
       
    }

    public static void main(String[] args) {
        new WFEngine().enterEventDispatcher();
    }
}

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

Re: NonPersistableObjectException

i would suggest that you use MVC and encapsulation, that would make it easier to read and analyze your code.

you call persistentobject.commit several times without actually changing the content of the persistant object. you have to call put prior to comitting.

the error you receive is caused by you trying to persist a primitive data type, int. only objects can be persisted. wrap your int into an Integer object prior to persisting.
----------------------------------------------------------
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.