on 05-15-2007 6:17 AM
Hi Experts
I am getting the Null Pointer Exception when I execute the following code. Can anybody please suggest where i am going wrong.
public void readInbox( )
{
//@@begin readInbox()
while (! wdContext.nodeEmail().isEmpty()) {
wdContext.nodeEmail().removeElement(wdContext.nodeEmail().getElementAt(0) );
}
wdContext.nodeEmail().invalidate();
Message[] message = new Message[1000];
IPublicEmailInteractiveFormComp.IEmailElement newEmailNodeElement;
//Set properties
// @TODO Enter your email server address here by replacing the text in angle brackets.
String host = "otemail.otegroup.com";
// @TODO Enter your email account here by replacing the text in angle brackets.
String username = "abc@otegroup.com";
// @TODO Enter your email account password here by replacing the text in angle brackets.
String password = "password";
Properties props = new Properties();
props.put("mail.smtp.host", host);
//Set Session
Session session = Session.getInstance(props, null);
//Set the store
try {
Store store = session.getStore("imap");
store.connect(host,username,password);
//Get folder
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
//Get Mails
message = folder.getMessages();
//Fill table with mails
for (int i = 0; i < message.length; i++)
{
if (message<i>.isSet(Flags.Flag.SEEN) == false)
{
if (message<i>.getSubject().equals("Travel Request Form"))
{
newEmailNodeElement = wdContext.createEmailElement();
newEmailNodeElement.setFrom(message<i>.getFrom()[0].toString());
newEmailNodeElement.setSubject(message<i>.getSubject());
newEmailNodeElement.setSentDate(message<i>.getSentDate().toString());
//Check for right Attachment
Object content = message<i>.getContent();
if ( content != null && content instanceof Multipart)
{
for (int j = 0 , n = ((Multipart)content).getCount(); j < n; j++)
{
Part part = ((Multipart)content).getBodyPart(j);
String disposition = part.getDisposition();
if ( disposition != null && (disposition.equals(Part.ATTACHMENT) || disposition.equals(Part.INLINE)))
{
if (part.getFileName().equals("TravelRequest.pdf"))
{
newEmailNodeElement.setAttachment(true);
newEmailNodeElement.setContentType(part.getContentType().toString());
InputStream is = part.getInputStream();
ByteArrayOutputStream bo = new ByteArrayOutputStream();
int c;
while ((c = is.read()) > -1) bo.write(c);
byte[] pdfSource = bo.toByteArray();
newEmailNodeElement.setPdfSource(pdfSource);
break;
}
else
{
newEmailNodeElement.setAttachment(false);
}
}
}
}
wdContext.nodeEmail().addElement(newEmailNodeElement);
}
}
}
//Close connection
folder.close(true);
store.close();
}
catch (MessagingException e)
{
wdComponentAPI.getMessageManager().reportSuccess(e.getMessage());
e.printStackTrace();
}
catch (IOException e)
{
wdComponentAPI.getMessageManager().reportSuccess(e.getMessage());
e.printStackTrace();
}
catch (NullPointerException e)
{
wdComponentAPI.getMessageManager().reportSuccess(e.getMessage());
e.printStackTrace();
}
//@@end
}
Regards
Abdullah
The error was caused when the subject used to return null
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.