Binou Dieng
Binou Dieng

Reputation: 57

java quartz cron schedule error

sorry for the english (i'm not a native speaker), i wanted to build a job for test.This job might just display a simple message "test job".I have build the classes but i have some errors that i don't really understand.

import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.impl.StdSchedulerFactory;

public class TestCrons {

        public static void main(String[] args) {
    // TODO Auto-generated method stub

        JobDetail job = new JobDetail();
        job.setName("dummyJobName");
        job.setJobClass(HelloJob.class);
        job.setGroup(Scheduler.DEFAULT_GROUP);


        CronTrigger trigger = new CronTrigger();
        trigger.setName("dummyTriggerName");
        trigger.setGroup(Scheduler.DEFAULT_GROUP);

        try {
         trigger.setCronExpression("0 0 11 18 * ?");

         //schedule it
         Scheduler scheduler = new StdSchedulerFactory().getScheduler();
         scheduler.start();
         scheduler.scheduleJob(job, trigger);

        }
       catch(Exception e)
       {

         System.out.println("erro :-p ");
         e.printStackTrace();
      }
 }

}

This is my HelloJob class

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

public class HelloJob implements Job{

@Override
   public void execute(JobExecutionContext arg0) throws JobExecutionException {
    // TODO Auto-generated method stub
    System.out.println("test job");

  }

}

When i run my TestCrons class i have this error :

java.lang.NullPointerException
at org.quartz.CronTrigger.computeFirstFireTime(CronTrigger.java:1086)
at org.quartz.core.QuartzScheduler.scheduleJob(QuartzScheduler.java:569)
at org.quartz.impl.StdScheduler.scheduleJob(StdScheduler.java:221)
at sn.orange.test.TestCrons.main(TestCrons.java:30)

Can anyone help me please.

Another question,why do i have applets which ask me authorizations when running TestCrons class ?

Upvotes: 0

Views: 1721

Answers (2)

Binou Dieng
Binou Dieng

Reputation: 57

Thank you Plabo Gallego,i have changed constructor.This is the code

import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.impl.StdSchedulerFactory;

public class TestCrons {

    public static void main(String[] args) {
    // TODO Auto-generated method stub
        try {
            JobDetail job = new JobDetail(Scheduler.DEFAULT_GROUP,"dummyJobName",HelloJob.class);

       CronTrigger trigger = new CronTrigger("TriggerGroup","dummyTriggerName","0 36 12 18 * ?");


             //schedule it
            Scheduler scheduler = new StdSchedulerFactory().getScheduler();
            scheduler.start();
            scheduler.scheduleJob(job, trigger);

           }
           catch(Exception e)
           {

              System.out.println("erro :-p ");
              e.printStackTrace();
          }
          }

    }

Upvotes: 0

You get a NullPointerException when using the no-arg constructor for CronTrigger if you don't set the start time yourself.

You'll need to make a call to setStartTime() or use a different constructor.

Upvotes: 1

Related Questions