2 fnzf14428547 fnzf14428547 于 2016.03.11 10:41 提问

启动一个定时任务就报错了

但是任务还是继续跑着

 2016-3-11 10:36:15 org.quartz.core.ErrorLogger schedulerError
严重: Unable to notify JobListener(s) of Job that was executed: (error will be ignored). trigger= group2.guanbi job= group2.job2
org.quartz.SchedulerException: JobListener 'dummyJobListenerName' threw exception: null [See nested exception: java.lang.NullPointerException]
    at org.quartz.core.QuartzScheduler.notifyJobListenersWasExecuted(QuartzScheduler.java:1987)
    at org.quartz.core.JobRunShell.notifyJobListenersComplete(JobRunShell.java:340)
    at org.quartz.core.JobRunShell.run(JobRunShell.java:224)
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
Caused by: java.lang.NullPointerException
    at test1.HelloJobListener.jobWasExecuted(HelloJobListener.java:37)
    at org.quartz.core.QuartzScheduler.notifyJobListenersWasExecuted(QuartzScheduler.java:1985)
    ... 3 more

下面是报错类的代码

 public class HelloJobListener implements JobListener {
    public static final String LISTENER_NAME = "dummyJobListenerName";
    @Override
    public String getName() {
        // TODO Auto-generated method stub
        return LISTENER_NAME;
    }

    @Override
    public void jobToBeExecuted(JobExecutionContext context) {
        String jobName = context.getJobDetail().getKey().toString();
        System.out.println("jobToBeExecuted");
        System.out.println("Job : " + jobName + " is going to start...");
    }

    @Override
    public void jobExecutionVetoed(JobExecutionContext context) {
        System.out.println("jobExecutionVetoed");
    }



    @Override
    public void jobWasExecuted(JobExecutionContext context,
            JobExecutionException jobException) {
        System.out.println("jobWasExecuted");

        String jobName = context.getJobDetail().getKey().toString();
        System.out.println("Job : " + jobName + " is finished...");

        if (!jobException.getMessage().equals("")) {
            System.out.println("Exception thrown by: " + jobName
                + " Exception: " + jobException.getMessage());
        }
    }

}

5个回答

wenxuechaozhe
wenxuechaozhe   2016.03.11 11:56

JobListener 'dummyJobListenerName' threw exception: null [See nested exception: java.lang.NullPointerException]
抛出的是空指针异常,建议断点跟进去看看哪里的get方法报错。

wenxuechaozhe
wenxuechaozhe 回复fnzf14428547: 看看context这个传递回来的是不是空,如果是跟上上一个方法看看是否值未取到然后抛的空指针异常。
接近 2 年之前 回复
fnzf14428547
fnzf14428547 没看出来。。。虽然定时任务可以跑,但是每跑一次报一次错
接近 2 年之前 回复
small_tu
small_tu   2016.03.11 12:00

Caused by: java.lang.NullPointerException
at test1.HelloJobListener.jobWasExecuted(HelloJobListener.java:37)

    第37行是什么?
fnzf14428547
fnzf14428547 就是下面的的代码啊
接近 2 年之前 回复
wangkang80
wangkang80   2016.03.11 12:47

关于spring和quartz的配置和使用,可参考:http://git.oschina.net/wangkang/llsfw

希望能够帮到你.

xionglangs
xionglangs   Rxr 2016.03.11 17:32

断点, at test1.HelloJobListener.jobWasExecuted(HelloJobListener.java:37)第37行报空指针。

Huakelilinjie
Huakelilinjie   2016.03.12 10:25
    String jobName = context.getJobDetail().getKey().toString();

这行空指针错误,加个点点看看你的 context是不是null,或者context.getJobDetail()是不是null

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!