I'm trying to create an .ics
file using ICal4j.
But when I try to add a recurrence it fails, throwing a ValidationException
:
net.fortuna.ical4j.model.ValidationException: Invalid property: RRULE at
net.fortuna.ical4j.model.Calendar.validate(Calendar.java:297) at
net.fortuna.ical4j.model.Calendar.validate(Calendar.java:257) at
net.fortuna.ical4j.data.CalendarOutputter.output(CalendarOutputter.java:96) at
net.fortuna.ical4j.data.CalendarOutputter.output(CalendarOutputter.java:83)
My code to add the recurrence is:
Recur recur = new Recur(Recur.WEEKLY,null);
recur.setUntil( new DateTime(dateTo.getTime()) );
RRule rule = new RRule(recur);
cal.getProperties().add(rule);
Without this rule it works fine, but I want to add this event every monday
until 12 December 2011
(the date returned by dateTo
). Any ideas?
A reccurrence rule (RRULE) property must be added to a specific event (VEVENT) in the calendar, not the calendar itself. e.g.
myEvent.getProperties().add(rule);
Also if you want the event to occur on a Monday you should probably use a rule like this:
FREQ=WEEKLY;BYDAY=MO;UNTIL=<date>
This is off the top of my head, so best to check the RFC to be sure:
https://www.rfc-editor.org/rfc/rfc5545#section-3.3.10
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With