1

I have a program that would send emails with attachments to users. The program should be ran according to the scheduled time, and because of that I use task scheduler to do it for me. I did all necessary steps to make this happen. (create .bat file to activate/run the jar file then task scheduler will trigger the .bat file if it hits the stated schedule.) The problem right now is that when the program is ran or is triggered by task scheduler, it gives off this error:

java.lang.NullPointerException
at sun.awt.shell.Win32ShellFolder2$1.call(Unknown Source)
at sun.awt.shell.Win32ShellFolder2$1.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at sun.awt.shell.Win32ShellFolderManager2$ComInvoker$3.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

I tried running it manually by using the .bat file and it works fine with no errors or whatsoever. I'm suspecting it has something to do with jFileChooser() because It wont retrieve the attachments in the default directory, but I'm not sure, there might be other causes. Here's the function that retrieves the attachments in the default directory:

 public String getMyDocument(String filename)
 {
     JFileChooser fr = new JFileChooser();
     FileSystemView fw = fr.getFileSystemView();
     return fw.getDefaultDirectory().toString()+"\\"+filename+".xls";
 }

PS.

All required attachments are present in the default directory, no misspelled words or misplaced characters. I also did some research but so far i haven't found any solutions yet.

3
  • Which task scheduler are you using? is it under windows? Oct 22, 2012 at 11:19
  • Yeap. Windows task scheduler.
    – jaycroll
    Oct 23, 2012 at 3:51
  • here's the content of the .bat file: java -jar EmailNotification.jar >> javalogs.txt
    – jaycroll
    Oct 23, 2012 at 4:27

1 Answer 1

0

Finally found the problem. I dropped the jfileChooser() and instead used getAbsolutePath().

public String getMyDocument(String filename)
 {
 String fileName = filename+'.xls';
 File attachmentFile = new File(fileName);
 String filePath = attachmentFile.getAbsolutePath().toString();
 return filePath();
 }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.