Results 1 to 5 of 5
  1. #1
    tweek's Avatar
    tweek is offline Member
    Join Date
    Jun 2011
    Location
    Bielsko-Biala, PL
    Posts
    3
    Rep Power
    0

    Default JavaMail nullPointerException while fetch messages

    Hi,

    I'm trying to set up application to receives emails from my gmail account using imap protocol. Everythinks was clear to me until fetch() messages.

    Here is my code:

    public static void main(String[] args) {
    IMAPFolder inbox;
    Properties properties = System.getProperties();
    properties.setProperty("mail.store.protocol", "imaps");

    try {
    Session session = Session.getDefaultInstance(properties, null);
    Store store = session.getStore("imaps");
    store.connect("imap.gmail.com", "********@gmail.com", "**********");

    inbox = (IMAPFolder) store.getFolder("Inbox");
    System.out.println("Unread messages count: " + inbox.getUnreadMessageCount());

    inbox.open(Folder.READ_WRITE);

    Message messages[] = inbox.search(new FlagTerm(new Flags(Flags.Flag.SEEN), false));

    FetchProfile fp = new FetchProfile();
    fp.add(FetchProfile.Item.CONTENT_INFO);

    inbox.fetch(messages, fp); // ERROR line

    for (Message mess : messages) {
    printMessage(mess);
    }

    inbox.close(true);
    store.close();


    } catch (NoSuchProviderException e) {
    e.printStackTrace();
    } catch (MessagingException e) {
    e.printStackTrace();
    }
    }



    and ERROR:

    Exception in thread "main" java.lang.NullPointerException
    at javax.mail.internet.ParameterList.set(ParameterLis t.java:165)
    at com.sun.mail.imap.protocol.BODYSTRUCTURE.parsePara meters(BODYSTRUCTURE.java:392)
    at com.sun.mail.imap.protocol.BODYSTRUCTURE.<init>(BO DYSTRUCTURE.java:232)
    at com.sun.mail.imap.protocol.BODYSTRUCTURE.<init>(BO DYSTRUCTURE.java:117)
    at com.sun.mail.imap.protocol.FetchResponse.parse(Fet chResponse.java:159)
    at com.sun.mail.imap.protocol.FetchResponse.<init>(Fe tchResponse.java:68)
    at com.sun.mail.imap.protocol.IMAPResponse.readRespon se(IMAPResponse.java:137)
    at com.sun.mail.imap.protocol.IMAPProtocol.readRespon se(IMAPProtocol.java:261)
    at com.sun.mail.iap.Protocol.command(Protocol.java:31 0)
    at com.sun.mail.imap.protocol.IMAPProtocol.fetch(IMAP Protocol.java:1312)
    at com.sun.mail.imap.protocol.IMAPProtocol.fetch(IMAP Protocol.java:1293)
    at com.sun.mail.imap.IMAPMessage.fetch(IMAPMessage.ja va:1045)
    at com.sun.mail.imap.IMAPFolder.fetch(IMAPFolder.java :1021)
    at com.springloops.ws.spike.EmailReceiveSpike.main(Em ailReceiveSpike.java:36)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.intellij.rt.execution.application.AppMain.main (AppMain.java:120)


    Any ideas what i did wrong?

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,790
    Rep Power
    25

    Default

    Are any of the variables used on that line null when it is executed?

  3. #3
    tweek's Avatar
    tweek is offline Member
    Join Date
    Jun 2011
    Location
    Bielsko-Biala, PL
    Posts
    3
    Rep Power
    0

    Default

    i didn't catch what do you mean by:
    Quote Originally Posted by Norm View Post
    Are any of the variables used on that line null when it is executed?

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,790
    Rep Power
    25

    Default

    Look at the line where the exception occurs?
    Look at each of the variables on that line.
    Are any of the variables used on that line null when that line is executed?

  5. #5
    tweek's Avatar
    tweek is offline Member
    Join Date
    Jun 2011
    Location
    Bielsko-Biala, PL
    Posts
    3
    Rep Power
    0

    Default

    I log all of these three variables used on this line and none is equal null :/

    It seems that the same exception occurs when I try to execute getContent() or getContentType on Message object.

Similar Threads

  1. Fetch Source Code
    By ujjwal in forum New To Java
    Replies: 7
    Last Post: 02-08-2011, 05:22 PM
  2. hibernate association fetch
    By enggvijaysingh@gmail.com in forum Advanced Java
    Replies: 1
    Last Post: 12-03-2010, 10:30 PM
  3. Fetch files over web server
    By Juuno in forum Networking
    Replies: 3
    Last Post: 02-19-2009, 03:02 PM
  4. Fetch Webpage - not working
    By jodyflorian in forum New To Java
    Replies: 5
    Last Post: 10-10-2008, 03:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •