1

我在我的项目中使用 JSF 和 EJB。

我有一个功能,我需要每 1 小时向某些人发送短信。

为此,我正在从数据库中获取我需要发送给的信息(某些人)。

从数据库中检索时,它会引发以下异常。

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

以下代码用于调度程序包 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();
    }
}
}

JobScheduler 的代码 import hms.db.PatientRegEMRemote; 导入 hms.db.Prescription;导入 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());
    }
}
}
4

1 回答 1

2

列出 pre=prescription_r.retrieveAll(s);

似乎处方_r 在这里显示为空。没有把握。只需检查断点即可。

于 2013-06-07T06:23:42.460 回答