Reputation: 297
I'm trying to add bank holidays from an ics calendar to an ArrayList of Date objects:
public void loadHolidays()
{
try {
URL holidays = new URL("https://www.gov.uk/bank-holidays/england-and-wales.ics");
InputStream fin = holidays.openStream();
CalendarBuilder builder = new CalendarBuilder();
Calendar calendar = builder.build(fin);
for (Iterator<?> i = calendar.getComponents().iterator(); i.hasNext();) {
Component component = (Component) i.next();
SimpleDateFormat fm = new SimpleDateFormat("yyyyMMdd");
publicHolidays.add(fm.parse(component.getProperty("DTSTART").getValue()));
}
System.out.println("\t\tSuccess.");
} catch (IOException e) {
System.out.println("\t\tFailed. www.gov.uk/bank-holidays/england-and-wales.ics does not exist.");
} catch (ParserException | ParseException e) {
System.out.println("\t\tFailed. Format changed in iCalendar");
}
}
However, I always get:
Exception in thread "main" java.lang.NoClassDefFoundError: net/fortuna/ical4j/data/ParserException at framework.GPSIS.main(GPSIS.java:29) Caused by: java.lang.ClassNotFoundException: net.fortuna.ical4j.data.ParserException
I have the imports in the beginning of the file:
import net.fortuna.ical4j.data.CalendarBuilder;
import net.fortuna.ical4j.data.ParserException;
import net.fortuna.ical4j.model.Calendar;
import net.fortuna.ical4j.model.Component;
And my .classpath contains:
<classpathentry exported="true" kind="lib" path="library/ical4j-1.0.5.jar"/>
I'm fairly new to Eclipse, and I'm trying to figure out what I'm missing here.
Upvotes: 2
Views: 1290
Reputation: 2074
The catch block for ParserException
is actually malformed. The pipe |
is usually used to catch several different exceptions in the same block (because you would handle them in the same way), and not twice the same exception:
catch(ParserException | ParserException e)
What happens here, is the java runtime matches the first ParserException against the import from ical4j, then looks for another ParserException to match the second one and doesn't find any.
Upvotes: 3