I have a strange situation here. I have a simple code looping through a text file for getting mail id's. If there is no mail id available then the code will sleep -> continue -> start of while. Every time i check whether i have anything in my string.IF no i will sleep again and try again. I have check on str.length()<5 (covering empty and null)/ i tried str.isEmpty + str.equals(null). All the time in the 3rd cycle the exceptions happens.
Code
public void sendButtonActionPerformed(java.awt.event.ActionEvent evt)
{
/* reading from text file at specific path*/
String str;
String attachment= "";
//String[] info = new String[2];
// int size = 0 ,i =0;
try{
FileReader fr=new FileReader("D:/data.txt");
BufferedReader br=new BufferedReader(fr);
///read line from the file upto null
while(true)
{
str=br.readLine();
System.out.println(str);
/* if( str.equals(null) )
{
System.out.println("sleeping1");
Thread.sleep(2000);
System.out.println("woke1");
continue;
}*/
if (str.length()<5)
{
System.out.println("sleeping");
Thread.sleep(2000);
System.out.println("woke");
continue;
}
globalMailCount++;
String[] info = str.split(";");
toAddress = info[0];
attachment = info[1]+ "";
// System.out.println("Email:"+toAddress+"image:"+attachment);
//System.out.println(info[i]);
ccAddress = "navaljosh@gmail.com";
subject = "Thanks from Jabong today";
message = "Hi, Thanks for being part of the event";
receipients = toAddress + "," + ccAddress;
receipientsList = receipients.split(",");
SendMailUsingAuthentication mailUsingAuthentication =
new SendMailUsingAuthentication();
try {
mailUsingAuthentication.postMail(receipientsList,
subject, message, "navaljosh@gmail.com", "sanmacs88", attachment);
} catch (MessagingException messagingException) {
messagingException.printStackTrace();
}
}
// br.close();
}catch(IOException e)
{
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Exception stack trace
sleeping
woke
sleeping
woke
sleeping
woke
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
null
at mailSent.MailSender.sendButtonActionPerformed(MailSender.java:169)
at mailSent.MailSender$1.actionPerformed(MailSender.java:65)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)