为什么在正确使用 ical4j 时会出现 ValidationException?

Why am I getting ValidationException while using ical4j properly?

我尝试用 ical4j 建立一个日历。当我试图将输出输出到一个文件时,它给了我一个如下所示的异常:

net.fortuna.ical4j.validate.ValidationException: Property [PRODID] must be specified once.

代码:

FileOutputStream icsOutputStream = new FileOutputStream(new File("").getAbsoluteFile()+ "classInfo.ics");
CalendarOutputter icsOutputter = new CalendarOutputter();
icsOutputter.output(ical4jHandler.icsCalender,icsOutputStream);

来自 ical4j documentation,您可以试试这个:

import net.fortuna.ical4j.model.Calendar;

// add this :
// create a new calendar
Calendar cal = new Calendar();
cal.getProperties().add(new ProdId("-//Ben Fortuna//iCal4j 1.0//EN"));
cal.getProperties().add(Version.VERSION_2_0);
// set other properties by looking at the documentation..

// your code 
FileOutputStream icsOutputStream = new FileOutputStream(new File("").getAbsoluteFile()+ "classInfo.ics");
CalendarOutputter icsOutputter = new CalendarOutputter();
// send the cal reference directly.
icsOutputter.output(cal,icsOutputStream);

请参阅文档了解更多信息。