0

我创建了一个调度程序:

SchedulerFactory sf = new StdSchedulerFactory();
Scheduler sched = sf.getScheduler();
Trigger trigger1 = (Trigger) 
newTrigger().withSchedule(DailyTimeIntervalScheduleBuilder.dailyTimeIntervalSchedule().startingDailyAt(new TimeOfDay(8,0)).endingDailyAt(new TimeOfDay(11,0)).withInterval(1, IntervalUnit.DAY));

Date ft = sched.scheduleJob(job, trigger1);

但它抛出了一个异常:

Exception in thread "main" java.lang.ClassCastException: org.quartz.TriggerBuilder cannot be cast to org.quartz.Trigger

我该如何解决这个错误?

4

1 回答 1

4

您忘记在TriggerBuilder上调用.build();方法。代码应如下所示:

newTrigger().withSchedule(
 DailyTimeIntervalScheduleBuilder.dailyTimeIntervalSchedule()
    .startingDailyAt(new TimeOfDay(8,0))
       .endingDailyAt(new TimeOfDay(11,0))
          .withInterval(1, IntervalUnit.DAY))
             .build();
于 2013-03-27T07:56:42.623 回答