我创建了一个调度程序:
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
如何解决此错误?
答案 0 :(得分:4)
您忘记在TriggerBuilder上调用.build();
方法了。代码应如下所示:
newTrigger().withSchedule(
DailyTimeIntervalScheduleBuilder.dailyTimeIntervalSchedule()
.startingDailyAt(new TimeOfDay(8,0))
.endingDailyAt(new TimeOfDay(11,0))
.withInterval(1, IntervalUnit.DAY))
.build();