Results 1 to 5 of 5
- 06-07-2011, 01:37 PM #1
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?
- 06-07-2011, 01:58 PM #2
Are any of the variables used on that line null when it is executed?
- 06-07-2011, 02:10 PM #3
- 06-07-2011, 02:16 PM #4
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?
- 06-07-2011, 02:28 PM #5
Similar Threads
-
Fetch Source Code
By ujjwal in forum New To JavaReplies: 7Last Post: 02-08-2011, 04:22 PM -
hibernate association fetch
By enggvijaysingh@gmail.com in forum Advanced JavaReplies: 1Last Post: 12-03-2010, 09:30 PM -
Fetch files over web server
By Juuno in forum NetworkingReplies: 3Last Post: 02-19-2009, 02:02 PM -
Fetch Webpage - not working
By jodyflorian in forum New To JavaReplies: 5Last Post: 10-10-2008, 02:49 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks