BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 05-08-2007, 03:44 AM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: berlin, germany
Model: 8310
PIN: N/A
Carrier: vodafone
Posts: 163
Post Thanks: 0
Thanked 0 Times in 0 Posts
Angry read message from INBOX

Please Login to Remove!

Hi,
i want to read the first message from my BlackBerry - INBOX.
I tried this one here:
Code:
Store stor = Session.getDefaultInstance().getStore();
           Folder[] folders2 = stor.list(Folder.INBOX);
           Folder infolder = folders2[0];  
           Message[] msgs = infolder.getMessages();
           Message inMsg = msgs[0]; // retrieve the first message
           Address[] recipients = inMsg.getRecipients(Message.RecipientType.TO);
           Date sent = inMsg.getSentDate();
           Address from = inMsg.getFrom();
           String subject = inMsg.getSubject();
           String txt = inMsg.getBodyText();
           Object o = inMsg.getContent();
            //verify that the message is not multipart
            if ( o instanceof String ) {
            String body = (String)o;
            }
           System.out.println(from+" | "+subject+" | "+txt);
But like the last days the compiler don't like my code very much :(
Quote:
unreported exception net.rim.blackberry.api.mail.MessagingException; must be caught or declared to be thrown
Message[] msgs = infolder.getMessages();

unreported exception net.rim.blackberry.api.mail.MessagingException; must be caught or declared to be thrown
Address[] recipients = inMsg.getRecipients(Message.RecipientType.TO);

unreported exception net.rim.blackberry.api.mail.MessagingException; must be caught or declared to be thrown
Address from = inMsg.getFrom();
this example is from the BlackBerry_Application_Developer_Guide_Volume_2.pd f

can anyone help me again, please

thx hibbert

[edit]
i found something new out:
Code:
Store store = Session.waitForDefaultSession().getStore();
             Folder folder = store.getFolder("SampleFolder");
but there the compiler also don't like the source:
Quote:
Originally Posted by compiler
unreported exception net.rim.blackberry.api.mail.NoSuchServiceException ; must be caught or declared to be thrown
Store store = Session.waitForDefaultSession().getStore();
unreported exception net.rim.blackberry.api.mail.FolderNotFoundExceptio n; must be caught or declared to be thrown
Folder folder = store.getFolder("SampleFolder");
i copied it 1:1 from the documentation, so why are there these errors ???

hibbert

Last edited by hibbert : 05-08-2007 at 04:01 AM. Reason: wonderfull new errors found :x
Offline  
Old 05-08-2007, 06:46 AM   #2 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: berlin, germany
Model: 8310
PIN: N/A
Carrier: vodafone
Posts: 163
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok, many probelms are solved, but not all ;)

here is my new sorce:
Code:
try {
                Store store = Session.waitForDefaultSession().getStore();
                try {
                Folder folder = store.getFolder("kein Service-Buch://Posteingang");
                Message[] msgs1 = folder.getMessages();
                int anzahl = msgs1.length;
                String blubb;
                blubb = "Anzahl1: "+anzahl;
                System.out.println(blubb); 
                } catch(MessagingException e) {
                }
                
                Folder[] folders = store.list(Folder.INBOX);
                for (int i = 0; i < folders.length; ++i) {
                String temp1 = folders[i].getFullName();
                temp1 = i + temp1;
                System.out.println(temp1);
                }
                
                Folder inbox = folders[0];
                System.out.println(inbox);
                System.out.println("noch gehts...0");
                    try{
                Message[] msgs = inbox.getMessages();
                System.out.println("noch gehts...1");
                int j=msgs.length;
                String bla;
                bla = "Anzahl: "+j;
                System.out.println(bla);
                if (j > 0) {
                Message inMsg = msgs[0]; // retrieve the first message
                System.out.println("noch gehts...2");
               // Address[] recipients = inMsg.getRecipients(Message.RecipientType.TO);
                System.out.println("noch gehts...3");
                //Date sent = inMsg.getSentDate();
                System.out.println("noch gehts...4");
                //Address from = inMsg.getFrom();
                String subject = inMsg.getSubject();
                String txt = inMsg.getBodyText();
                Object o = inMsg.getContent();
                    //verify that the message is not multipart
                if ( o instanceof String ) {
                    String body = (String)o;
                }
                System.out.println(subject+" | "+txt);
            }
                
                    } catch (MessagingException e) {
                    System.err.println("ERROR ==> "+e);
                    } 
                System.out.println(folders[0].getFullName());
                
                //int j=messages.length; 
                
                //*/
             }catch (NoSuchServiceException e) {
                System.out.println("ERROR => "+e.toString());
             }
             }
This code works on my BlackBerry. At least I have 3 mail in my Inbox ("Posteingang"), but everytime I retrieve a "0"
Quote:
Originally Posted by compiler
Anzahl1: 0
0kein Service-Buch://Posteingang
kein Service-Buch://Posteingang
noch gehts...0
noch gehts...1
Anzahl: 0
kein Service-Buch://Posteingang
So i think i'm in the wrong folder, or? So how can I get the right one?

thx hibbert
Offline  
Old 05-08-2007, 06:47 AM   #3 (permalink)
Knows Where the Search Button Is
 
Join Date: May 2007
Model: 8707
PIN: N/A
Carrier: Proximus
Posts: 16
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Hibbert,

I'm using part of this code too in an application, but I get the same errors ...mail.MessagingException; must be caught or declared to be thrown.
Could this have something to do with the imports in the beginning of the code or with accessibility of variables/objects?

L J.
Offline  
Old 05-08-2007, 07:11 AM   #4 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: berlin, germany
Model: 8310
PIN: N/A
Carrier: vodafone
Posts: 163
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by L Jorissen View Post
Hello Hibbert,

I'm using part of this code too in an application, but I get the same errors ...mail.MessagingException; must be caught or declared to be thrown.
Could this have something to do with the imports in the beginning of the code or with accessibility of variables/objects?

L J.
I just set a try - catch block around some lines and it works...

but now i have a new problem: I can't get the mails from the inbox (see my second post)
hibbert

[edit]
ah ok, it was really the wrong folder. now it works as it should do ;)
[/edit]

Last edited by hibbert : 05-08-2007 at 07:44 AM. Reason: solution found
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.