Parser Exception

Help
Anonymous
2013-01-28
2013-06-05

  • Anonymous
    2013-01-28

    Hi,
    I am trying to Parse a ical file from google Calendar but it keeps saying:

    net.fortuna.ical4j.data.ParserException: Error at line 1:Expected [BEGIN], read [<HTML>]
    Built
        at net.fortuna.ical4j.data.CalendarParserImpl.assertToken(CalendarParserImpl.java:477)
        at net.fortuna.ical4j.data.CalendarParserImpl.assertToken(CalendarParserImpl.java:452)
        at net.fortuna.ical4j.data.CalendarParserImpl.parse(CalendarParserImpl.java:114)
        at net.fortuna.ical4j.data.CalendarBuilder.build(CalendarBuilder.java:210)
        at net.fortuna.ical4j.data.CalendarBuilder.build(CalendarBuilder.java:191)
        at net.fortuna.ical4j.data.CalendarBuilder.build(CalendarBuilder.java:179)
        at net.fortuna.ical4j.util.Calendars.load(Calendars.java:94)
        at Main.<init>(Main.java:42)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at java.lang.Class.newInstance0(Unknown Source)
        at java.lang.Class.newInstance(Unknown Source)
        at sun.applet.AppletPanel.createApplet(Unknown Source)
        at sun.applet.AppletPanel.runLoader(Unknown Source)
        at sun.applet.AppletPanel.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
    

    Its a very simple Program , it just builds the Calendar. What could be the problem?

    The URL I am tryng to Parse is http://www.google.com/calendar/ical/m0es4hhj4g9d69ibak88tvoup0%40group.calendar.google.com/public/basic.ics

    My Code (I am using ical4j 1.0.4) :

    final String EXAM_URL = "http://www.google.com/calendar/ical/m0es4hhj4g9d69ibak88tvoup0%40group.calendar.google.com/public/basic.ics";
    
            Calendar calendar = null;
            try {
                calendar = Calendars.load(new URL (EXAM_URL));
            } catch (MalformedURLException e) {
    
                e.printStackTrace();
    
            } catch (IOException e) {
    
                e.printStackTrace();
    
            } catch (ParserException e) {
    
                e.printStackTrace();
    
            }
    
            System.out.println("Built");
    
     
  • Ben Fortuna
    Ben Fortuna
    2013-01-28

    Hello,

    It looks like there is a problem accessing the URL, most likely a 404 or something like that. The indicator is that you are getting HTML content rather than ICS content ("Expected , read ") .

    Try using URLEncoder to encode your URL string (or maybe even URLDecoder as it already appears to be encoded). Experimentation should help you get to the ICS content.

    regards,
    ben

     

  • Anonymous
    2013-01-29

    Thanks Ben,
    After a bit of experimenting as you suggested, I figured out that Google Calendar only allowed HTTPS connections. So changed the URL to https:\… and it worked.