title: quartz threw an unhandled Exception: : java.lang.NullPointerException with JSF+EJB
body: <p>I am using JSF and EJB in my project.</p>
  
  <p>I have one functionality where i need to send the sms to some people for every 1 hour.</p>
  
  <p>For that i am getting the information(some persons) from the database to whom i need to send.</p>
  
  <p>While retrieving from the database it is throwing the following exceptions.</p>
  
  <pre><code>09:51:29,640 ERROR [org.quartz.core.JobRunShell] (DefaultQuartzScheduler_Worker-2) Job group1.job1 threw an unhandled Exception: : java.lang.NullPointerException
  at hms.general.SendSMSJob.execute(SendSMSJob.java:43) [classes:]
  at org.quartz.core.JobRunShell.run(JobRunShell.java:213) [quartz-all-2.1.7.jar:]
  at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557) [quartz-all-2.1.7.jar:]
  
  09:51:29,640 ERROR [org.quartz.core.ErrorLogger] (DefaultQuartzScheduler_Worker-2) Job (group1.job1 threw an exception.: org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: java.lang.NullPointerException]
  at org.quartz.core.JobRunShell.run(JobRunShell.java:224) [quartz-all-2.1.7.jar:]
  at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557) [quartz-all-2.1.7.jar:]
  Caused by: java.lang.NullPointerException
  at hms.general.SendSMSJob.execute(SendSMSJob.java:43) [classes:]
  at org.quartz.core.JobRunShell.run(JobRunShell.java:213) [quartz-all-2.1.7.jar:]
  ... 1 more
  </code></pre>
  
  <p>The following code is for scheduler
      package hms.general;</p>
  
  <pre><code>import javax.faces.bean.ApplicationScoped;
  import javax.faces.bean.ManagedBean;
  
  import org.quartz.JobDetail;
  import org.quartz.Scheduler;
  import org.quartz.SchedulerException;
  import org.quartz.Trigger;
  import org.quartz.impl.StdSchedulerFactory;
  
  
  @ManagedBean(eager=true)
  @ApplicationScoped
  public class ScheduleBean {
  public ScheduleBean() {
      try{
          Scheduler scheduler =  StdSchedulerFactory.getDefaultScheduler();
          scheduler.start();
  
          JobDetail job = org.quartz.JobBuilder.newJob(SendSMSJob.class).withIdentity("job1","group1").build();
          Trigger trigger = org.quartz.TriggerBuilder.newTrigger().withIdentity("trigger1","group1").startNow().withSchedule(org.quartz.SimpleScheduleBuilder.simpleSchedule().withIntervalInHours(1).repeatForever()).build();
          scheduler.scheduleJob(job,trigger);
  
      }
      catch(SchedulerException se){
          se.getMessage();
      }
  }
  }
  </code></pre>
  
  <p>Code for JobScheduler
      import hms.db.PatientRegEMRemote;
      import hms.db.Prescription;
      import hms.db.PrescriptionEMRemote;</p>
  
  <pre><code>import java.util.List;
  
  
  import javax.ejb.EJB;
  
  import org.quartz.Job;
  import org.quartz.JobExecutionContext;
  import org.quartz.JobExecutionException;
  
  public class SendSMSJob implements Job {
  
  @EJB(mappedName = "java:global/Hms-Main/PatientRegEM!hms.db.PatientRegEMRemote")
  public PatientRegEMRemote patreg_r;
  
  @EJB(mappedName = "java:global/Hms-Main/PrescriptionEM!hms.db.PrescriptionEMRemote")
  private PrescriptionEMRemote prescription_r;
  
  public static void main(String ar[]){
      SendSMSJob hj = new SendSMSJob();
      try {
          hj.execute(null);
      } catch (JobExecutionException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  }
  @Override
  public void execute(JobExecutionContext arg0) throws JobExecutionException {
      System.out.println(arg0.getJobDetail());
      System.out.println("I am in execute method....");
      // TODO Auto-generated method stub
      System.out.println("Im inside execute method");
      String s="select p from prescription p where p.smsflag=1";
      System.out.println(s);
      List&lt;Prescription&gt; pre=prescription_r.retrieveAll(s);
      System.out.println(".........");
      for (Prescription p : pre) {
          System.out.println(p.getAppointno());
      }
  }
  }
  </code></pre>