Session.waitForDefaultSession () .getStore () is null

in the blackberry Simulator anyting is ok, but when I put my BlackBerry smartphone are null;

This code is in an Application, which is the enforcement function automatic startup, when I debug in my camera, find is null.

but I'm doing a new apps, set it in a Uiapplication screen, everything is fine,

I do why

"no BlackBerry plan.

That will probably explain the null value.

Anyway, you shouldn't test things like that at startup until the device is completely upward.  Simon provided little code to do.  Personally, I prefer the approach presented in this article, although it is a bit more complicated:

http://supportforums.BlackBerry.com/T5/Java-development/write-safe-initialization-code/Ta-p/444795

Once you get past the boot, you need to allow the treatment to deal with obtaining a null session default if you want to test on packages BlackBerry devices.

I think these two points together should solve your problem.

Tags: BlackBerry Developers

Similar Questions

  • Application crashes with "Store store = Session.waitForDefaultSession () .getStore ();

    Hello

    I am trying to delete the emails of my device but my application crashes when I try to fulfill the purpose of the Bank to "Store store = Session.waitForDefaultSession () .getStore (); This line.

    He works on a simulator and removes all mails, but on the device, it crashes...

    Why this is happening?

    Any idea?

    Please let me know...

    Thank you...

    Check this thread
    http://supportforums.BlackBerry.com/T5/Java-development/check-if-quot-device-can-send-email-quot-EMA...

  • Add forlder listener in Inbox

    Hello.

    I use 8700 device and I am interested in fixing of lead below her question for OS 4.0 and higher.

    Here is a sample of BlackBerry Development Guide of how to do to add the listener to the Inbox:

    Store is Session.waitForDefaultSession () .getStore ();.
    Records file [] = store.list (Folder.INBOX);
    Inbox folder = files [0];
    inbox.addFolderListener (listener);

    At first glance, it's pretty simple. But it does not work! In fact, it works sometimes but only for the first message that fall to the Inbox. Sometimes. And sometimes it's not even the first message chat. I tried to add the listener to all subfolders recursively, but had the same result:

    Store is Session.waitForDefaultSession () .getStore ();.
    attachToInbox (store.list (Folder.INBOX), listener);

    private public static Sub attachToInbox (file [] files, FolderListener listener)
    {
    for (int i = 0; i)< folders.length;="">
    {
    Folders [i] .addFolderListener (Listener);
    attachToInbox (folders [i] .list (Folder.INBOX), listener);
    }
    }

    Someone at - it secret of the RIM on Inbox? How to heal the bug?

    Thank you very much

    Please take a look at the following article in the knowledge base developer.

    What's – the application is not notified when new messages arrive
    Article number: DB-00153

    http://www.BlackBerry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800698/What_Is...

  • Save the PhoneListener and the FolderListener in a single application

    If I'm around all blackberry applications, when I get a phone call, I'm able to display a popup once the call is answered for example. But if I get an email, I'm not able to display any popup screen, even if I see the messagesAdded() get me fired and also the popupscreen is invoked as I reinforced with debugging.

    The mechanism that I use to view the popuscreen phone and Email is the same, but the event of phone works and not the event of enamel.

    Here is what I do

    AutoStart calls my main class

    public final class myMain {}
           
    {private myMain()
    try {}
    Phone.addPhoneListener (new ConcretePhoneListener());
    Store is Session.waitForDefaultSession () .getStore ();.
    store.addFolderListener (new ConcreteEmailListener());
    }
    catch (Exception e) {}
    //
    }
    }
       
    Public Shared Sub main (String [] args) {}
    PAP PimAssistantMain = new PimAssistantMain();
    }
    }

    In my ConcretePhoneListener(), this is how I invoke the popup screen

    SerializableAttribute public class ConcretePhoneListener extends AbstractPhoneListener {}
       
    private void somePrivateMethod() {}

    UiApplication.getUiApplication () .invokeLater (new Runnable() {}
    public void run() {}

    UiApplication.getUiApplication () .pushScreen (new PhonePopupScreen());

    }
    });

    }

    }

    the code above works, but

    / public class ConcreteEmailListener implements FolderListener {}
       
    private void somePrivateMethod() {}

    UiApplication.getUiApplication () .invokeLater (new Runnable() {}

    public void run() {}

    UiApplication.getUiApplication () .pushScreen (new EmailPopupScreen());

    }

    });

    }

    }

    the above code IS NOT working for some reason any in the sense that, when new email arrives, I don't see the screen like the one for the phone, the event popup not.

    In the EmailPopupScreen() and PhonePopupScreen(), I would go the PopupScreen and make sure that the screen is in the foreground by using the code below

    protected void onObscured() {}
    UiApplication.getUiApplication () .requestForeground ();
    }

    Can someone tell me first if I'm heading in the right direction and also explain this strange difference in the behavior for these 2 types of events and how the email event a popup screen

    First off let me say that I have NOT actually tried a screen on an email listener, so this might not work, but I might be able to help.

    First of all, to look for a couple of things

    UiApplication.getUiApplication ()...

    Do not forget that this gets a reference to the UiApplication who is running, not your application.  So if you run in the earpiece of the phone you are running in the phone, in the listener of e-mail application, you run in the messaging application.

    protected void onObscured() {}
    UiApplication.getUiApplication () .requestForeground ();
    }

    onObscured is called when the screen is covered by another screen.  If she does not, she will not be called.  Assume its display, the screen masking came from the same application which displays on the screen, then the requestForeground() will not do anything, because the Application is always in the foreground.  If the screen masking done from another application, then it is possible that this would actually hide the new screen.  I think that's why do you afterwards.

    These points side lets talk about why it works for the phone and not by e-mail.  Easy, I think.  The earpiece of the phone runs in the phone application, which of course is in the foreground when the phone is used.  That means the app phone is to put in the background when it finishes.  So if you press a screen in the foreground when executing the application phone will display, it could disappear - that's why I think that the use of the requestForeground() in the onObscured().

    However, the messaging application works in the background at the time of the invocation of the listener. Thus, while pushing the screen won't get on the screen.  So to get this screen, the application must be on the foreground.

    I hope that a shed.

    Now, I would say, rather than push these screens using the actual RIM applications, skip this treatment to your own application, and then you have the control over the treatment of foreground/background.  Probably the best way to proceed is to use a Global event, extract the data you want the listener, talk to your application, and then deal with this in your own application.

    Edit: My apologies for this suggestion of duplication - I just changed when RexDoug

  • How to check if the e-mail account is defined or not?

    Hello

    my application crashes to "Store store = Session.waitForDefaultSession () .getStore () this line, because it does not account for the email set.

    We can check programmatically if the e-mail account is set or not?

    If you have any ideas please share.

    Thank you...

    http://supportforums.BlackBerry.com/T5/Java-development/check-if-quot-device-can-send-email-quot-EMA...

  • Add and delete a Listner folder to store

    I'm developing an application with the api Folderlistner... I can get all mails from my store, I had 2 problems in my application

    I can't quit smoking folderlistner. use

    removelistner method when calling exit (system.exit) after tat my request for treatment of all email for example my request to delete all emails from my store. How to delete store folderlistner

    When restart it my application processing emails once more, I want to say 2 headphones, working at the same time not only 2

    For each restart another a listner shoud added

    How can I solve this problem?

    the addition of listner

    mystore= session.getStore();
    mystore.addFolderListener(this);
    

    in removeing llistner, while calling system.exit (0)

    mystore.removeFolderListener(this);
    mystore=null;
    

    To create an instance of singleton you need not another entry point. I was referrring you to this part of the code and not the application complete. Just set up the next part in your application and no need for alternate entry point parameters.

    private FolderListenerGUI folderListenerGUI = null;
    
      //Long value: com.samples.folderListener
    
      public static final long RTSID_MY_APP = 0x7451402f595f81a5L;
    
      public FolderListenerApp() 
    
      {
    
        try
    
        {
    
          //Get the store from the default instance.
    
          Store store = Session.getDefaultInstance().getStore();
    
          //Add the folder listener to the store.
    
          store.addFolderListener(this);
    
        }
    
        catch (Exception e)
    
        {
    
          System.out.println(e.toString());
    
        }
    
      }
    
      //Returns an instance of the running FolderListenerApp.
    
      public static FolderListenerApp waitForSingleton()
    
      {
    
        //Ensure this is a singleton instance.
    
        //Open the RuntimeStore.
    
        RuntimeStore store = RuntimeStore.getRuntimeStore();
    
        //Obtain the reference of FolderListenerApp.
    
        Object obj = store.get(RTSID_MY_APP);
    
        //If obj is null, there is no current reference
    
        //to FolderListenerApp. Start a new instance
    
        // of FolderListenerApp if one is not running.
    
        if (obj == null)
    
        {
    
          //Store a reference to this instance in the RuntimeStore.
    
          store.put(RTSID_MY_APP, new FolderListenerApp());
    
          return (FolderListenerApp)store.get(RTSID_MY_APP);
    
        } else
    
        {
    
          return (FolderListenerApp)obj;
    
        }
    
      }
    

    Kind regards

    yosoh

  • Attempt to send Email but no success

    Hello guys,.

    I wrote a code to send an Email. But not send Mail. The Code is below

    sending class extends screen
    {
    Its session = null;
    public sending()
    {
    Try
    {
    its = session.getDefaultInstance ();
    Store store = null;
    Transport tp = null;
    if(ses!=null)
    {
    Store = its .getStore ();
    TP = its .getTransport ();
    }
    String emailAddress = "[email protected]";
    If ((Store!=null) & (tp! = null))
    {
    E-mail message = New Message();
    If (emailAddress! = null &! emailAddress.equals(""))
    {
    email.addRecipient (Message.RecipientType.TO, new Address (emailAddress, emailAddress));
    }
    Void String = null;
    String content = 'This is first BB to Yahoo email';
    void = "Hello Nitin";
    email.setSubject (sub);
    email.setContent (happy);
    TP. Send (email);
    System.out.println ("Success sending Email");
    }
    on the other
    {
    System.out.println ("could not send emails");
    }
    } catch (Exception ex) {}
    }
    }

    What I would do.

    The best link I can give you is that you already have - the search button.  I suggest that you use.  Then you will find the article for this problem and other resources that will be useful for other problems you will have.

    You also help us to help by answering the questions that people ask and working on the problem yourself.  If you say

    "I want to know what is the problem with this Code."

    can you ask someone to read your code, test, understand, guess your test environment and then guess where is the problem and try to write a response.  It's a lot of work.  You need to make it easy for people to help you.  Then tell us exactly what you're doing, how you are testing, and what you see.  Then we can focus on where the problem is in fact rather than trying to figure out where it is.

    I think you will find an answer to your problem in this thread:

    http://supportforums.BlackBerry.com/T5/Java-development/sending-mail-with-OS-4-2-code-snippet/TD-p/5...

  • Sending mail with OS 4.2, extracted code.

    Hello

    I found some code snippets that show me how to send an email using the blackberry 4.2 API or higher.

    Y at - there someone who can help me find a code snippet or he can share with us?

    Do I need to know the SMTP host, username, password, server port, ecc in my software to send an email, or I can get these data from the phone?

    Help, please.

    Here's some code I've used in the past:

    try {}
    A session = Session.getDefaultInstance ();
    Store store = null;
    Transport tp = null;

    If (session! = null) {}
    Store = session.getStore ();
    TP = session.getTransport ();
    }

    Sting emailAddress = "UPGRADE EMAIL ADDRESS HERE";

    If ((magasin! = null) & (tp! = null)) {}
    E-mail message = New Message();
    If (emailAddress! = null &! emailAddress.equals("")) {}
    System.out.println ("emailAddress ===>" + emailAddress);
    email.addRecipient (Message.RecipientType.TO, new address)
    emailAddress, emailAddress));
    }

    Void String = null;

    content = "PUT YOUR BODY TEXT HERE";

    void = "SET TOPIC HERE";

    email.setSubject (sub);
    email.setContent (happy);
    TP. Send (email);
    System.out.println ("inside the sendEmail (/success)");

    } else {}
    retVal = false;
    ("System.out.println("[SendEmail/SendEmail ()] Email not configured, cannot send email ');
    }

    } catch (Exception e) {}
    retVal = false;
    System.out.println ("email");
    }

  • Send an email with an attachment image

    trying to send an email with a picture of an attachment but I'm not able to open the image sideways recipient - he says that the image is corrupted

    any help would be appreciated!

    Here is the code:

    public static void sendEmailWithAttachment(String to, String subject, Bitmap image) {           //create a multipart            Multipart mp = new Multipart();         //data for the content of the file          //String fileData = "just a simple test";          //String messageData = "Mail Attachment Demo";          PNGEncoder encoder = new PNGEncoder(image, true);           byte[] b = null;            try {               b = encoder.encode(true);           } catch (IOException e1) {              // TODO Auto-generated catch block              e1.printStackTrace();           }           SupportedAttachmentPart sap = new SupportedAttachmentPart(mp,"image/png","x-rimdeviceimage.png",b);         /*TextBodyPart tbp = new TextBodyPart(mp,"Send Image");         //add the file to the multipart         mp.addBodyPart(tbp);*/          mp.addBodyPart(sap);            //create a message in the sent items folder         Folder folders[] = Session.getDefaultInstance().getStore().list(Folder.SENT);           Message message = new Message(folders[0]);          //add recipients to the message and send            try {                Address toAdd = new Address(to,to);                 Address toAdds[] = new Address[1];              toAdds[0] = toAdd;              message.addRecipients(Message.RecipientType.TO,toAdds);                 message.setContent(mp);                 message.setSubject(subject);                Transport.send(message);                Dialog.inform("Card was sent to " +to);            } catch (Exception e) {              Dialog.inform(e.toString());           }       } 
    

    I could send it properly after the conversion of the image in JPEG format

    JPEGEncodedImage jpegImage = JPEGEncodedImage.encode(image,100);                        //data for the content of the file           SupportedAttachmentPart sap = new SupportedAttachmentPart(mp,jpegImage.getMIMEType() ,"x-rimdeviceimage.jpg",jpegImage.getData() );
    
  • Mail API BlackBerry question

    Good afternoon

    I'm looking for a way to get the e-mail address of the person who SENDS a message when a message is sent from the device. So, if I send an email via my blackberry to Suzy, when I call this API, I get [email protected]12xxxxx. A quick check of getFrom() gives a NULL value.

    Any suggestions?

    Hi, if you are looking for the identification of default email for which the BB device is configured, try this...

    Session.waitForDefaultSession () .getServiceConfiguration () .getEmailAddress)

    TNX.

  • How to read all the emails

    Hi, what is the code used to read all the emails the user has received.

    I know how to add a file listener to read all the new messages, but how do I read the oldest.

    for example, a message was received until the user starts the application.

    thanx

    Hi thanks for the reply.

    How ever that has not worked for me.

    But I found the solution

    http://supportforums.BlackBerry.com/T5/forums/Searchp age/tab/message? page = 2 & location = category % 3Aap...

    Store store = Session.getDefaultInstance().getStore();
    
    Folder[] folders = store.list(Folder.INBOX);
    Folder inbox = folders[0];
    Message[] msgs = null;
    try {
    msgs = inbox.getMessages();
    } catch (MessagingException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    
  • Choice of one account to send emails from

    Hello world. I tried to find a way allow a user to select the account they wish to send. I managed to make a dialog screen that allows the selection of the user an email address of a contact if they have multiple addresses for the recipient and want to do the same thing to address. I came across this piece of code on the forum.

    Public Store getStore (String regEmail)
    {
    Full book sb = ServiceBook.getSB ();
    SRS [] ServiceRecord = sb.getRecords ();
    for (cnt int = srs.length - 1; cnt > = 0; cnt-) {}
    If (srs [cnt] .getCid () .equals ("CMIME')) {}
    ServiceConfiguration sc = new ServiceConfiguration (srs [cnt]);
    If (SC. GetEmailAddress(). Equals (regEmail))
    {
    Store is Session.getInstance (sc) .getStore ();.
    store return;
    }
    }
    }
    Return Session.getDefaultInstance () .getStore ();
    }

    What should I do for this code to get all the e-mail addresses of the unit and display them? I guess I do. getEmailAddress() for each srs [] element is that correct?

    Stone as always you have been a great help. I had to work very quickly with your code snippet.

    I added this to the constructor of the screen:

    String [] fromAddresses = getOurEmailAddresses();

    Dialog dlg = new dialogue ("Select which address to use.",)

    fromAddresses, null, 0.

    Bitmap.getPredefinedBitmap (Bitmap.QUESTION));

    int selectedAddr = dlg.doModal ();

    String selectedEmail = fromAddresses [selectedAddr];

    from.setText (selectedEmail);

    Thank you once again.

  • E-mail Info curve8310 using Java BlackBerry GPS

    Here is the code for blackberry GPS information sent to an e-mail address. The code uses sleep to send information at intervals.

    My problem is that when once that the GPS goes out of scope the application stops sending emails and no exception is thrown.

    If (lp! = null)

    {code}

    Sleep (65000);

    But it did not work for me.

    ////////

    public void run() {}
    While (! _stop) {}
    Address one;
    Store is Session.getDefaultInstance () .getStore ();.
    Records file [] = store.list (Folder.SENT);
    Folder sentfolder = files [0];
    Message m = new Message (sentfolder);
    SimpleDateFormat sdf;
                  
    try {}
    LP LocationProvider = LocationProvider.getInstance (null);
    If (lp! = null) {}
    Location = lp.getLocation (60);
    Coordinates of c = l.getQualifiedCoordinates (); get the GPS coordinates
                           
    If (c! = null) {}
    Lat string = Double.toString (c.getLatitude ()); Latitude
    LNG chain = Double.toString (c.getLongitude ()); Longitude
    String alt = Float.toString (c.getAltitude ()); altitude
    Tim string = Long.toString (l.getTimestamp ()); timestamp
    String spd = Float.toString (l.getSpeed ()); Speed
                               
    String orgstr = "0449953853", + tim + ',' + lat + ',' lng + ',' + ', ' + alt;
    String googmap =http://maps.google.com/maps?q= "+ lat + ',' + LNG;
    String finalstr = orgstr + "\n" + googmap;
    a = new address ("[email protected]", "Aditya Tuli";)
    Address address [] = {a};
    m.addRecipients (Message.RecipientType.TO, addresses);
    m.setContent (finalstr);
    m.setSubject ("GPS Position";)
    Transport.Send (m);
    }
    } sleep (65000); moved to re - run the thread
    } catch (Exception e) {}
    System.Err.println ("an error occurred" + try ());
    System.Exit (0);
    }
    }
    }

    ///////

    Please suggest.

    Thanks in advance.

    Concerning

    I think we have agreed that the problem is that it is there no LocationProvider or the getLocation is not a place, so to determine which of them seems to be the best place to start.  As you test on the device, you must debug on the device, you can connect by USB, starting the JDE, using the Debug/Attach To / Pocket PC, then select USB connected device.

    From there, you should be able to use the JDE debug, but according to levels, this sometimes does not work so well for me.  So I would like to add three statements of System.out.println (...), one at the beginning of the loop and the others inside each of the ' if.  This load on the device, then, once debugging started, simply wait for the missing output for each loop!

    Who help me?

  • No messages in Inbox

    Hello

    I'm trying to get the messages from the Inbox. But the store.list () function does not give me the right folder.

    I want to have 'Desktop://myName/serverName/inbox '.
    But I don't you 'Desktop://myName/serverName/sent' and 'draft '.
    the only Inbox folder that I get is "no servicebook://inbox" and there is not my emails to incommed.

    Here my code to inspect the records.
    Try
    {

    Store is Session.getDefaultInstance () .getStore ();.
    Records file [] = store.list ();
    Dialog.Inform (String.valueOf (Folders.Length));
    for (int i = 0; i)< folders.length="" ;="">
    {
    inboxFolder = files [i];
    Dialog.Inform (inboxFolder.GetFullName ());
    Message input [] = inboxFolder.getMessages ();
    If (input.length == 0)
    {Dialog.inform ("leer") ;}
    on the other
    {
    Most recent message = input [0];

    Dialog.Inform (Newest.getSubject ());
    }
    }
    }
    catch (Exception e) {Dialog.inform (try ()) ;}}

    Please help me.

    Martin

    Edit: I use the JDE 4.2 for 8700v BB don't

    Search recursively for the Inbox folder.

    See this article.

    http://www.BlackBerry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800698/What_Is...

  • Listener e-mail about all message boxes

    Hi all

    I tried to implement (what I thought was) a receiver of simple messages. I have the code in its own class that implements FolderListener, according to which everything he needs to do is to recover messages sent to any of the message boxes that the device has. After that, it will check certain properties of the message, but I'm stuck at the real listener/detection part.

    Using the BB code has tried to extract "INBOX" of type "Folder" and by adding the listener to this, but since entered an approach more high level that performs this action throughout the store:

    class MailListener extends MainManager implements FolderListener {
      Message _newMessage;
      String _cipherText;
    
      MailListener() {
        Session.getDefaultInstance().getStore().addFolderListener(this);
      }
    
      public void messagesAdded(FolderEvent event) {
        _newMessage = event.getMessage();
    
        UiApplication.getUiApplication().invokeLater(new Runnable() {
            public void run() {
              Dialog.alert("Got an email");
            }
        });
      }
    }
    

    However, on receipt of an email, the message "to receive an email' fails to display - makes me think of the earpiece does not work properly, as the call of Dialog.alert works well if it is placed in the constructor.

    Can you see where I am going wrong?

    Thank you!

    Will be

    Here's a slightly more updated version of the article you found:

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

    The approach to the use of a Global event and FolderListener is the recommended approach for this kind of requirement.  Recommended, because it is safe, made the appropriate context for you and isolates the treatment of electronic mail (which exists in the earpiece of your file) from your code.

    There are other means, less fresh generals and/or coding of requirement, but there is no safer way.

    As an example of another way, you might have shared in RuntimeStore storage space.  You could have a treatment of your Application that expects data to be included in the RuntimeStore collection.  Then the listener needs to do is pop the data in the RuntimeStore - your Application running in its own context, will pick up these data and can treat it as he likes.

    By the way the reference will not work, because you always have the problem of running your code in another context.

    I tried to explain the basics of Applications and their context (or address spaces, or whatever you want to call them), in this post.

    http://supportforums.BlackBerry.com/T5/Java-development/ControlledAccess-exception-for-persistent-St...

Maybe you are looking for