user2314868
user2314868

Reputation: 129

quartz threw an unhandled Exception: : java.lang.NullPointerException with JSF+EJB

I am using JSF and EJB in my project.

I have one functionality where i need to send the sms to some people for every 1 hour.

For that i am getting the information(some persons) from the database to whom i need to send.

While retrieving from the database it is throwing the following exceptions.

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

The following code is for scheduler package hms.general;

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 for JobScheduler import hms.db.PatientRegEMRemote; import hms.db.Prescription; import hms.db.PrescriptionEMRemote;

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<Prescription> pre=prescription_r.retrieveAll(s);
    System.out.println(".........");
    for (Prescription p : pre) {
        System.out.println(p.getAppointno());
    }
}
}

Upvotes: 1

Views: 4919

Answers (1)

Shailesh Pratapwar
Shailesh Pratapwar

Reputation: 4224

List pre=prescription_r.retrieveAll(s);

Seems like prescription_r is appearing null here. Not sure. Just check with breakpoint.

Upvotes: 2

Related Questions