在 运行 的同时获取 "cannot convert from TriggerBuilder<Trigger> to Trigger" 简单的 Quartz 教程程序
Getting "cannot convert from TriggerBuilder<Trigger> to Trigger" while running simple Quratz tutorial program
我是 java Quartz 调度的新手,一直在尝试 运行 来自 youtube 教程的简单 quartz 程序。
这是我试过的代码:
public class drive1 {
public static void main(String[] args) throws SchedulerException {
JobDetail jobDetail = JobBuilder.newJob(Job.class).build();
Trigger trigger = TriggerBuilder.newTrigger().withIdentity("SimpleTrigger").startNow();
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
scheduler.start();
scheduler.scheduleJob(jobDetail, trigger);
}
}
这一直在第 4 行给我编译错误:
Type mismatch: cannot convert from TriggerBuilder<Trigger> to Trigger
所以我尝试在第 4 行显式类型转换:
Trigger trigger = (Trigger)TriggerBuilder.newTrigger().withIdentity("SimpleTrigger").startNow();
这消除了编译错误,但现在我收到 运行 时间异常:
Exception in thread "main" java.lang.ClassCastException: org.quartz.TriggerBuilder cannot be cast to org.quartz.Trigger
at sd.moc.drive1.main(drive1.java:18)
有人可以帮帮我吗?
我知道这是一个菜鸟问题,但我是新手。
我相信你需要'build'触发器。所以你需要改变
Trigger trigger = TriggerBuilder.newTrigger().withIdentity("SimpleTrigger").startNow();
至
Trigger trigger = TriggerBuilder.newTrigger().withIdentity("SimpleTrigger").startNow().build();
我是 java Quartz 调度的新手,一直在尝试 运行 来自 youtube 教程的简单 quartz 程序。
这是我试过的代码:
public class drive1 {
public static void main(String[] args) throws SchedulerException {
JobDetail jobDetail = JobBuilder.newJob(Job.class).build();
Trigger trigger = TriggerBuilder.newTrigger().withIdentity("SimpleTrigger").startNow();
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
scheduler.start();
scheduler.scheduleJob(jobDetail, trigger);
}
}
这一直在第 4 行给我编译错误:
Type mismatch: cannot convert from TriggerBuilder<Trigger> to Trigger
所以我尝试在第 4 行显式类型转换:
Trigger trigger = (Trigger)TriggerBuilder.newTrigger().withIdentity("SimpleTrigger").startNow();
这消除了编译错误,但现在我收到 运行 时间异常:
Exception in thread "main" java.lang.ClassCastException: org.quartz.TriggerBuilder cannot be cast to org.quartz.Trigger
at sd.moc.drive1.main(drive1.java:18)
有人可以帮帮我吗? 我知道这是一个菜鸟问题,但我是新手。
我相信你需要'build'触发器。所以你需要改变
Trigger trigger = TriggerBuilder.newTrigger().withIdentity("SimpleTrigger").startNow();
至
Trigger trigger = TriggerBuilder.newTrigger().withIdentity("SimpleTrigger").startNow().build();