PersistentObject is null

Hey. PhoneBill is in production now and I'm starting a new project (while retaining the PB) - thank you all.

On the new project, some small old lessons may need to learn fast.


    public static void main(String[] args)
    {

            // Recreate start stuff
            synchronized (store) { 

                StoreInfo info = new StoreInfo();

                info.setElement(StoreInfo.NUMBEROFSEARCHTERMSTRINGS, "1");
                info.setSearchTerms(0, "forest");

                _data.removeAllElements();
                _data.addElement(info);

                store.setContents(_data);
                store.commit();

            }

As this small store thing is null in the synchronized line (store). This is the first time I ran the thing. If it's something stupid I forgot, apologies in advance. All links to the articles on the first allocation of permanent storage to a new application may also help.

Why has the null value of the store (a PersistentObject) Please?

J

you need to generate the object first of course.

Store = PersistentStore.getPersistentObject (1234);

then the store will not be null (content may be null of course)

what I usually do then is:

code is hacked out of my head, may contain errors

{Synchronized (Store)}

Object content = store.getContent ();

if(Content == null) {}

content = new Object();

store.setContent (content);

Store.Commit ();

}

content.doStuff ();

}

Tags: BlackBerry Developers

Similar Questions

  • Persistent object Null pointer exception

    Hi all! This is my first time that you try to use persisted data and, as a result of the Bberry tutorial, I'm a JVM 104 "NullPointer Exception" when you try to synchronize and "setContents' in a new Bank persistence (so basically my"PersistentObject"is Null (as confirmed by the debug), which I suppose that logic since I have not stored all the data it again.) I guess I'm just curious as to why I get this error (and cannot just write something on the value "null"). Here is a code...

    public static PersistentObject levels = PersistentStore.getPersistentObject (0x3e1f605d47578703L);

    ...

    String [] level_info = {'0', '1'}; just to test

    Synchronized (levels) {//this is where I get the error of debugging of "NullPoint Exception", where levels = "null"

    levels.setContents (level_info);
    Levels.Commit ();

    }

    Thank you in advance for your help!

    I solved the problem by displaying the 4.6 JDE 'samples' tutorial persistentstoredemo...

    You can find it here on your PC:

    C:\Program search in Motion\BlackBerry JDE 4.6.0\samples\com\rim\samples\device\persistentstoredemo

    Thank you

    -Jordan

  • Problem with PersistentObject.

    Hi all

    I am new to the BB and bad English (I'm Thai), sorry if you confuse in my words. I have a project that has thead to download the server image and record in PersistentObject using my CustomHashTable. The problem is that I have an error message "NonPersistableObjectException", which is based on the method "persistentObject.commit ();" in "getEncodedImage()" when I debug, here is my code.

    public class TestApp extends UiApplication{
    
        public static void main(String[] args) {      UiApplication app = new TestApp();        app.enterEventDispatcher();   }
    
      TestApp(){        pushScreen(new TestScreen()); }}
    
    public class TestScreen extends MainScreen{
    
       EncodedImage encodedImage;    CustomHashTable persistentHashtable;  private DataInputStream dis;  private byte[] encodeData;    private ByteArrayOutputStream byteStream; PersistentObject persistentObject = PersistentStore.getPersistentObject(0x61a0ab9f850b5c9bL);
    
      TestScreen(){     super();      if (persistentObject.getContents() == null) {         persistentHashtable = new CustomHashTable();          persistentObject.setContents(persistentHashtable);            persistentObject.commit();        }else {           persistentHashtable = (CustomHashTable)persistentObject.getContents();        }     encodedImage = getEncodedImage("http://download.magikmobile.mobi/scodp/mpreview.do?idc=683979&size=140x90&","4952","hot");       encodedImage = scaleImage(encodedImage);
    
          this.setTitle("Test my app");     this.add(new BitmapField(encodedImage.getBitmap()));  }
    
      public EncodedImage scaleImage(EncodedImage image) {      int displayWidth = Fixed32.toFP(Display.getWidth());      int imageWidth = Fixed32.toFP(image.getWidth());      int scalingFactor = Fixed32.div(imageWidth, displayWidth);        EncodedImage scaledImage = image.scaleImage32(scalingFactor, scalingFactor);      return scaledImage;   }
    
      public EncodedImage getEncodedImage(String url, String id, String catagory) {
    
           EncodedImage enc = null;      if (persistentHashtable.containsKey("EncodeImage01")) {           enc = (EncodedImage)persistentHashtable.get("EncodeImage01");     }
    
            if (enc != null) {          System.out.println(">>>>>  image not null");            return enc;        } else {            System.out.println(">>>>>  image null");            try {                String newURL = null;                while (url.indexOf("&") > 0) {                    newURL = url.substring(0, url.indexOf("amp;"));                    url = url.substring(url.indexOf("amp;") + 4);                    url = newURL + url;                }
    
                    newURL = null;                String suffix = "";                HttpConnection httpConnection = (HttpConnection) Connector.open(url+suffix);                httpConnection.setRequestMethod(HttpConnection.GET);                if (httpConnection.getResponseCode() == 302) {                   boolean b = true;                    while (b) {                        if (httpConnection.getResponseCode() == 200) {                            b = false;                            break;                        }                        httpConnection = (HttpConnection) Connector.open(httpConnection.getHeaderField("Location"));                    }                }                dis = httpConnection.openDataInputStream();                int length = (int) httpConnection.getLength();                if (length > 0) {                    encodeData = new byte[length];                    dis.readFully(encodeData);                } else {                    byteStream = new ByteArrayOutputStream();                    int ch;                    while ((ch = dis.read()) != -1) {                        byteStream.write(ch);                    }                    encodeData = byteStream.toByteArray();                    byteStream.close();                    byteStream = null;                }                dis.close();                dis = null;                httpConnection.close();                httpConnection = null;                try {                    enc = EncodedImage.createEncodedImage(encodeData, 0, encodeData.length);                } catch (OutOfMemoryError e) {                  System.out.println(">>>>  OutOfMemoryError");                    e.printStackTrace();                    return null;                } catch (NullPointerException e) {                 System.out.println(">>>>  NullPointerException");                    e.printStackTrace();                    return null;                } catch (IllegalArgumentException e) {                 System.out.println(">>>>>  IllegalArgumentException");                    e.printStackTrace();                    return null;                } catch (ArithmeticException e) {                  System.out.println(">>>>  ArithmeticException");                    e.printStackTrace();                    return null;                }                encodeData = null;                persistentHashtable.put("EncodeImage01", enc);                persistentObject.commit();                catagory = null;                id = null;                url = null;                return enc;            } catch (SecurityException ex) {                ex.printStackTrace();                return null;            } catch (IOException ex) {                ex.printStackTrace();                return null;            }        }    }
    
    }
    
    public class CustomHashTable extends Hashtable implements Persistable{
    
    }
    

    What should I do?

    Thank you very much

    ~ MazMellow ~.

    I see no problem here, hashtable will have any object as second parameter to the function, so you can put hashtable in storage of place (it is supported and commonly used):

    Hash hash = new Hashtable();

    data Byte [] = image.getData ();

    Hash.put ("first", data);

    ....

    ...

    ...

    ....

    data Byte [] (byte []) = hash.get ("first");

    image = EncodedImage.createEncodedImage (data,...);

  • Store the object in a persistent storage

    Hello

    I want to store the cusom object in the persistent store.here is my custom class:

    public class {UserData

    OrgName string;
    Time to string;
    String authTocken;
    Public UserData (orgName, String authTocken, String time, String)
    {
    this.orgName = orgName;
    This.Time = time;
    this.authTocken = authTocken;

    }
    public String getOrgName() {}
    return orgName;
    }
    {} public void setOrgName (String orgName)
    this.orgName = orgName;
    }
    public String getTime() {}
    back in time;
    }
    {} public void setTime (string time)
    This.Time = time;
    }
    public String getAuthTocken() {}
    Return authTocken;
    }
    {} public void setAuthTocken (String authTocken)
    this.authTocken = authTocken;
    }

    }

    and I use the following class of persistent storage to store the data.

    / public final class PersistentStoreContents implements {Persistable
    private CAMailMinderHashTable mElements = null;
    static private instance of PersistentStoreContents = null;
    Private static final long KEY = 0x67c5b66a2bcd1dfcL;
    private PersistentObject persistentObject = null;

    /**
    * Gets the single instance of the database.
    *
    * only @return of the database instance
    */
    public static getInstance() {} PersistentStoreContents
    try {}
    If (instance == null) {}
    Logger.out ("PersistentStoreInfo", "creation of the storage object");
    instance = new PersistentStoreContents();
    }
    } catch (Exception e) {}
    instance = null;
    }
    return instance;
    }

    private PersistentStoreContents() {}
    persistentObject = PersistentStore.getPersistentObject (KEY);
    synchronized (persistentObject) {}
    If (persistentObject.getContents () == null) {}
    persistentObject.setContents (new CAMailMinderHashTable());
    persistentObject.commit ();
    }
    }

    mElements = persistentObject.getContents ((CAMailMinderHashTable));
    If (mElements == null) {}
    Logger.out ("PersistentStoreInfo", "*" + (mElements is nothing));
    mElements = new CAMailMinderHashTable();
    }

    }

    public String getElement (String key) {}
    Logger.out ("PersistentStoreInfo", "getElement:" + key);
    Return (String) mElements.get (key);
    }

    ' Public Sub setElement (String key, String value) {}
    Logger.out ("PersistentStoreInfo", "setElement:" + key + value);
    mElements.put (key, value);
    persistentObject.setContents (mElements);
    persistentObject.commit ();
    }

    UserData public getElement2 (String key) {}
    Logger.out ("PersistentStoreInfo", "getElement:" + key);
    Return mElements.get (key) (UserData);
    }

    public void setElement2 (String key, UserData userData) {}
    Logger.out ("PersistentStoreInfo", "setElement:" + key);
    mElements.put (key, userData);
    Logger.out ("PersistentStoreInfo", "added");
    persistentObject.setContents (mElements);
    Logger.out ("PersistentStoreInfo", "game content");
    persistentObject.commit ();
    Logger.out ("PersistentStoreInfo", "Validate");
    }

    Public list getAllKeys() {}
    Logger.out ("PersistentStoreInfo", "getElement:" + key);
    Return mElements.keys ();
    }
    }

    I use the follwinng code to insert data :

    PersistentStoreContents ch = PersistentStoreContents.getInstance ();
    UserData = us new UserData("gmail.com","1111","aaaa");
    ps.setElement2 ("[email protected]", US);

    But it is not inserting data in the persistent store. App is struck to the persistent store setContent method... any idea on this?

    the object you put in the store has implemented persistable, not your utility class.

  • Need help with PersistentStorage

    Hi all,

    I am writing to request that the use of PersistendObject.

    long key = 0x47ce7a00e2b74d73L;

    PersistentObject dataStore = null;
    data store = PersistentStore.getPersistentObject (key);
    Synchronized (datastore)
    {
    dataStore.setContents (v);
    dataStore.commit ();
    }

    My Question is the above program

    What is the value of using keys key.what?

    I would cite a long value or a specific value? If it is positive or negative? any other value.

    Thanks in advance

    Sorry for my English

    Check this developer doc and section data storage.

    http://NA.BlackBerry.com/eng/deliverables/7682/BlackBerry_Java_Development_Environment-4.7-us.PDF

  • problem when getting the value of the persistent object

    Hello

    I am trying to store the State of registration of the user in my App I have used persistent store. But I don't get the bak of the store database. I wrote the code below:

    package com.saiservices.util;
    
    import java.util.Enumeration;
    
    import com.saiservices.ui.Logger;
    
    import net.rim.device.api.system.PersistentObject;
    import net.rim.device.api.system.PersistentStore;
    import net.rim.device.api.util.Persistable;
    
    public class SaiPersistentStore implements Persistable{
    
        private SaiHashTable mElements = null;
        static SaiPersistentStore instance;
        private static final long KEY = xxxxxxxxxxxx;
        private PersistentObject persistentObject = null;
    
        /**
         * Gets the single instance of DataBase.
         *
         * @return single instance of DataBase
         */
        public static SaiPersistentStore getInstance() {
            try {
                if (instance == null) {
                    instance = new SaiPersistentStore();
                }
            } catch (Exception e) {
                instance = null;
            }
            return instance;
        }
    
        private SaiPersistentStore()
        {
             Logger.out("PersistentStoreInfo", "inside constructor  ");
            persistentObject = PersistentStore.getPersistentObject(KEY);
             synchronized (persistentObject)
               {
                   if (persistentObject.getContents() == null)
                   {
                       persistentObject.setContents(new SaiHashTable());
                       persistentObject.commit();
                   }
               }
    
             mElements = (SaiHashTable)persistentObject.getContents();
             if (mElements == null){
                 Logger.out("PersistentStoreInfo", "************"+(mElements == null));
                 mElements = new SaiHashTable();
             }
        }
    
        public String getElement(String key)
        {
            Logger.out("PersistentStoreInfo", "getElement :"+key);
            Logger.out("PersistentStoreInfo", "getElement value   :"+mElements.get(key));
    
            return (String) mElements.get(key);
        }
    
        public void setElement(String key, String value)
        {
            Logger.out("PersistentStoreInfo", "setElement11111 :"+key + "   "+value);
            mElements.put(key, value);
            persistentObject.setContents(mElements);
            Logger.out("PersistentStoreInfo", "setElement22222 :"+key+"   "+value);
            persistentObject.commit();
        }
    
        public Enumeration getAllKeys()
        {
            return mElements.keys();
        }
    
    }
    

    And here's the code for hash table:

    package com.saiservices.util;
    
    import java.util.Hashtable;
    
    import net.rim.device.api.util.Persistable;
    
    public class SaiHashTable extends Hashtable implements Persistable{
    
        public SaiHashTable(){
            super();
        }
        public SaiHashTable(int initialCepacity){
            super(initialCepacity);
        }
    
    }
    

    Now, I'll put the element as follows:

    SaiPersistentStore.getInstance (.setElement("Registration","on"));

    But when I try to get the item in a way theis, gettting null value:

    SaiPersistentStore.getInstance () .getElement ("Register")

    Where I am doing wrong here?

    The fixed. Key hash table was different. Change it and it works...

  • Function of recharging of the screen

    Here's what I'm trying to accomplish

    1. run screen, but make the configuration checks.

    1 test issit 1st time straight thru

    persistentObject = PersistentStore.getPersistentObject (KEY);
    If (persistentObject.getContents () == null) {/ / run the Welcome screen}

    2. If so, run the screen of welcome instead of the screen. The next screen is configuration screen.

    3 setupscreen.close, save all the settings.

    4. return to 1.

    Here's my problem: when setupscreen.close (this.close ()), it goes back to the screen of welcome instead of the screen.

    I tried invalidate(), but in vain.

    My skaleton is something like this:

    It is the basis

    package net.test.my;
    
    import net.rim.device.api.ui.UiApplication;
    
    public class ptApplication extends UiApplication {
    
        public ptApplication() {
            ptMainScreen mainScreen = new ptMainScreen();
            pushScreen(mainScreen);
        }
    
        public static void main(String[] args) {
            ptApplication app = new ptApplication();
            app.enterEventDispatcher();
        }
    }
    

    It is screen

    package net.test.my;
    // imports stuff
    
    public class ptMainScreen extends MainScreen implements FieldChangeListener {
    
    // var declarations
    
        public ptMainScreen() {
    
            persistentObject = PersistentStore.getPersistentObject(KEY);
            if (persistentObject.getContents() == null) {
                   //Welcome screen with "Setup" button
                   //call to ptSetupScreen via userSettings               } else {
                       //display real mainscreen
            }
    }
    private void userSettings() {        ptSetupScreen setupScreen = new ptSetupScreen();        UiApplication.getUiApplication().pushScreen(setupScreen);    }
    
    // fieldChanged and stuffs
    

    ptSetupScreen

    package net.test.my;
    
    // import stuffs 
    
    public class ptSetupScreen extends MainScreen implements FieldChangeListener {
        public ptSetupScreen() {
                  // setup screen
                  // save data then this.close
        }
    }
    

    I suggest read you the developer's guide and study some of the samples.

    pushscreen (mainscreen)

    pushscreen (welcomescreen)

    in welcomescreen, button, popscreen (welcomescreen) and pushscreen (optionsscreen)

    in optionsscreen, popscreen (optionsscreen)

    -> visible screen is screen

  • PersistentObject null pointer

    I'm trying to store data in the persistentObject, following the example in the following document,

    http://docs.BlackBerry.com/en/developers/deliverables/635/BlackBerry_Java_Development_Environment_De...

                    storeInfo = new StoreInfo();
    
                    storeInfo.setElement(StoreInfo.COMPANYID, txtAccess.getText().toString());
                    storeInfo.setElement(StoreInfo.USERNAME, txtUser.getText().toString());
                    storeInfo.setElement(StoreInfo.PASSWORD, txtpass.getText().toString());
                    storeInfo.setElement(StoreInfo.STATUS, "SAVED");
    
                    _data.addElement(storeInfo);
    
                    synchronized(store){
                        store.setContents(storeInfo);
                        store.commit();
                    }
    

    I get the error pointer null to synchronized (store)

    I declare the following store

    private static PersistentObject store;
    

    I read what the error, I think it means that I don't have any initailised store, however I don't know how to initialize it.

    found the solution

    PersistentObject store = PersistentStore.getPersistentObject (PERSISTENT_STORE_DEMO_ID);

  • PersistentObject.getContents () returns null after app update

    Hello

    I'm trying to track down a bug with PersistentStore.
    Usually when I update the app I get the getContents() stored content.
    However, something in the code has changed from one version to the other and now getContents() returns null.

    I made sure the id has never changed for PersistentStore.getPersistentObject (id);
    I made sure that we use the same basic sdk (4.3.0)
    I made sure that there are the data stored in the stored hash table

    Currently, it's a hash table - no subclass (even though I know that I should change it to a subclass when it's fixed);

    I wonder if there are any suggestions on what might cause the getContents() return null - or which could result in the PersistentStore have cleared.

    What information is needed, please let me know and I'll paste.

    I found the problem after.

    Classes have begun to obscure differently. If the hash table was still readable, but because he could not read the content of the hash table, he would return null.

    It was unexpected, because if you have a custom class persisted and you try to read it, you will get the content, but you can't cast. But with the hash table, it does not return the content (uncastable) and it throws no exceptions...

    I hope this helps someone else who has a similar problem.

  • PersistentObject and problem SendListener

    I recorded a SendListener in order to intercept outgoing e-mail. When my manager is called I want to access my application stored in PersistentObject settings to determine what I should do in my manager of sendMessage.

    The problem is that I can't access any information contained in my application. I suspect that it is because my manager sendMessage runs in the context of the mail application.

    Should which design I follow to access my store persistent since a manager like this?

    Thank you

    John.

    I must admit, I have not really tested recently myself, but as far as I know, you should be able to access your persistent objects - assuming that you are running by using your own code and persistent objects classes, the framework should not matter.

    Can you describe the problem when you try to access the information?  If your objects seem to be "null" then I guess you use static references.  static variables are specific to a context, then your listener will see different static variables for your application.

    The reason why I've not tested this recently is that the normal practice for Auditors is change in context of your Application, and the usual approach is via a GlobalEvent

    http://supportforums.BlackBerry.com/T5/Java-development/global-events-and-global-event-listeners/TA-...

  • make null pointer exception when accessing a persistent in UIApplication storage

    Hi, I do an apps which depends on a persistent storage, it checks the value, if the screens of its 'regtrue', load screen1 otherwise. I'm getting to chain data.getMessage () null pointer exception

    public class uiApp extends UiApplication {}
      
    Public Shared Sub main (String [] args) {}
    Data StorePersistent = new StorePersistent();
    PAP uiApp = new uiApp();
    theApp.enterEventDispatcher ();
    }
    public uiApp()
    {StorePersistent data = new StorePersistent();
    String gotMsg ="";
    PersistentObject store = PersistentStore.getPersistentObject (0x946aa64a17ee9165L);
    synchronized (store) {}
    data = new StorePersistent();
    data = (StorePersistent) store.getContents ();
    if(Data == null) {}
    data = new StorePersistent();
    }
    Store.Commit ();
    }
    gotMsg = data .getMessage ();
    If (gotMsg.equalsIgnoreCase ("Regtrue"))<------------------------NULL>
        
        
          
    pushScreen (new login()));

    on the other

    pushScreen (new MenuScreen2());
    }
    }

    SRY, it was a stupid mistake, I was retrieving information that was never stored

  • NullPointerException on PersistentObject problem

    * Update * I can solve the problem now! I did not know that I have to put a comment with the string KEY in the code... how silly I am (> / / /)<>

    Hello!

    I'm developing an application with EditField. I need the EditField to store it that the user entered, so I tried to write the code (using the example found on the Internet)...

    private static PersistentObject myobject;
        static
        {
            //*****I have no idea what 0xe63e08aacd575338L is, just copy it from the Internet...
            myobject = PersistentStore.getPersistentObject(0xe63e08aacd575338L);
        }
    
    String[]storedV = (String[])myobject.getContents();
    
    if (storedV != null)
            {
                f1Field.setText(storedV[0]);
                f2Field.setText(storedV[1]);
            }
    
            f1Field = new EditField("Username:","");
            add(f1Field);
            f2Field = new PasswordEditField("Password:","");
            add(f2Field);
    
    String unameToSave = f1Field.getText();
                String pwdToSave = f2Field.getText();
                String[] storeV = {unameToSave,pwdToSave};
                synchronized(myobject)
                {
                    myobject.setContents(storeV);
                    myobject.commit();
                }
    

    With this code, everything went well when I run for the first time (if there is no value stored in PersistentStore).

    When I run for the second time, I got "Eception Exception: NullPointerException ' on the line

     f1Field.setText(storedV[0]);
    

    Please help me!

    Thanks in advance for any answer!

    PS. I use this Simulator 8520...

    0xe63e08aacd575338L is, just copy it from the Internet...
    

    Do not copy a key key somene else... or you will eventually damage the memory of each and other.  Use a unique key, pass around some of these figures in something different

    Regarding the nullpointer, try to add a control to ensure that the field is not null

  • Auto unblocking "null" Apple Watch

    My Apple Watch connects my rMBP and everything with macOS Sierra very well, but when my watch sends me a notification says "null" unlocked by this Apple Watch. How to replace the text "null"?

    Solved it for me by signing in and out of the iCloud on mac + iphone then restart all 3.

  • Siri in him sending text with the value 'NULL '.

    When I say, "Siri, text my wife, 'X', ' Siri responds correctly,"here is your message to Jill: 'X'. "" "  "Ready to send it?"  I say 'Yes' and sends the message.  As soon as I get a text from my carrier saying the recipient of the message was invalid.  100% of the time, I see that Siri has sent a text with the value NULL.

    I tried to restart my phone.  I tried to remove and re-add my contacts.  Anyone else having this problem?  Someone knows how to solve?

    If it's by the carrier, you should contact them and see what they receive in return for their side. Ive had Siri send messages for me and I have never seen this one IOS.

  • Talk to the text sent by 'null '.

    When I try and talk to the text of my husband, it continues to send "null" while Siri said she looks and she is sending.  It works with my two other friends who have iPhones.  Suggestions?  I already turned my phone market.

    I guess "speak text" means:

    • You use Siri to send a message.
    • You send it to an iPhone.
    • The message is sent using iMessage (which may or may not be true, even if your husband has an iPhone).
    • The message is not part of a thread existing, but is actually starting a new message thread.

    So presumably, you call Siri to send a message to your husband's iPhone and dictate the content of the message to Siri.

    Assuming that it actually sent via iMessage (blue bubble), check the settings > Messages > Send and receive > start new Conversations on and see it is set correctly.

Maybe you are looking for

  • Bootcamp in macOS Sierra

    Hello I'm using bootcamp on macOS Sierra (on MacBook Air 2015) and had installed Windows 10. I don't know if I can ask this group, but I think that the problem is a problem of bootcamp. When I turn on the computer to start Windows under bootcamp, it

  • Drive necessary recovery for Qosmio F20

    I lost my recovery disc for my laptop Qosmio F20-104 (I don't remember if he even came with any!). How do I restore my laptop to zero?I have the disk utilities and tools, but unfortunately, that's all... Help! Thank you Gee

  • touch my key I push each 2 seconds?

    can no longer quickly type, have to hold down the keys for 2 seconds. to get the answer

  • Setting paper painted with API

    I'm putting the peripheral background, however, I keep getting errors when using the API I've followed this documentation, setting the wallpaper of the Unit regarding: https://developer.BlackBerry.com/Cascades/reference/bb__platform__homescreen.html#

  • Nvidea geforce 210 driver

    After you have not used my computer for several months, I decided to get out of storage and started using it again. After several updates that have been made, I noticed that windows has stopped my video card to work correctly, stating there are a few