BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 08-26-2007, 07:50 PM   #1 (permalink)
Thumbs Must Hurt
 
Spartan115's Avatar
 
Join Date: Aug 2007
Model: Pearl
PIN: N/A
Carrier: T-Mobile
Posts: 80
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with Store.getFolder()

Please Login to Remove!

I'm just writing a little program for my Pearl that listens for email messages (in Java) Here is the relevant code:
Code:
 public void messagesAdded(FolderEvent e) {
        //Lets get the added message
        Store store = Session.waitForDefaultSession().getStore();
        Folder folder = Store.getFolder("INBOX");
        Message msgs[] = folder.getMessages();
        Message msg = msgs[0];
        //Now lets find out who sent the message
        Address from = msg.getFrom();
        //If the message is from dshipper@gmail.com then make the phone ring
        if(from.toString().equals("dshipper@gmail.com")){
           InputStream is = getClass().getResourceAsStream("sound.wav");
           Player p = Manager.createPlayer("http://216.7.189.162/globe/realtones/appliance/phonesring.wav");
            p.start();
        }
        else{
           InputStream is = getClass().getResourceAsStream("sound.wav");
           Player p = Manager.createPlayer("http://216.7.189.162/globe/realtones/appliance/phonesring.wav");
            
            p.start();
        }
        
    }
So the problem is that when I use Store.getFolder, it says that I can
t use a non-static method in a static context. But even when I create new classes in new class files that are obviously non-static it still doesn't let me do it. What am i doing wrong?
Thanks in advance
Offline  
Old 08-26-2007, 11:31 PM   #2 (permalink)
Thumbs Must Hurt
 
Join Date: Jun 2007
Location: Bangladesh
Model: 8800
PIN: N/A
Carrier: EDGE
Posts: 93
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Spartan115,

Quote:
Originally Posted by Spartan115 View Post
Code:
Store store = Session.waitForDefaultSession().getStore();
        Folder folder = Store.getFolder("INBOX");
        Message msgs[] = folder.getMessages();
Complete the following possible solutions for this issue:
Code:
Store store = Session.waitForDefaultSession().getStore();
store.addFolderListener(new FolderListener() {
   public void messagesAdded(FolderEvent e) {
       if( e.getMessage().isInbound() == true )
       {
           //message is a new received message
           //perform some task here
       }
   }
   //implement other FolderListener methods
   //...
});
Hope this will meet your requirements!

Cheers,
ARIF
Offline  
Old 09-02-2007, 10:39 PM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: Apr 2005
Model: 950
Carrier: T-Mobile
Posts: 185
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Maybe you want a lowercase s for Store?

Jon
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.