DefaultTimeZoneRegistryFactory Error

Help
Anonymous
2012-07-27
2015-09-23
  • Anonymous - 2012-07-27

    Hi,

    I'm trying to parse a downloaded ical file in an android project with ical4j.

    I have added the following files to my libs directory and added them into the build path using the android plugin.

    backport-util-concurrent-3.1.jar, commons-codec-1.5.jar, commons-lang-2.6.jar, commons-logging-1.1.1.jar, ical4j-1.0.3.jar
    

    I am getting an error when I call

    CalendarBuilder builder = new CalendarBuilder();
    

    The error is

    07-28 00:46:08.362: I/Configurator(19472): ical4j.properties not found.
    07-28 00:46:08.392: W/dalvikvm(19472): Exception Ljava/lang/NullPointerException; thrown while initializing Lnet/fortuna/ical4j/model/TimeZoneRegistryImpl;
    07-28 00:46:08.392: I/SyncAdapter(19472): Closing network connection and releasing provider.
    07-28 00:46:08.412: W/dalvikvm(19472): threadid=11: thread exiting with uncaught exception (group=0x40a3c1f8)
    07-28 00:46:08.412: E/AndroidRuntime(19472): FATAL EXCEPTION: SyncAdapterThread-1
    07-28 00:46:08.412: E/AndroidRuntime(19472): java.lang.ExceptionInInitializerError
    07-28 00:46:08.412: E/AndroidRuntime(19472):    at net.fortuna.ical4j.model.DefaultTimeZoneRegistryFactory.createRegistry(DefaultTimeZoneRegistryFactory.java:48)
    07-28 00:46:08.412: E/AndroidRuntime(19472):    at net.fortuna.ical4j.data.CalendarBuilder.<init>(CalendarBuilder.java:123)
    07-28 00:46:08.412: E/AndroidRuntime(19472):    at ie.clashoftheash.timetabler.syncadapter.SyncAdapter.onPerformSync(SyncAdapter.java:109)
    07-28 00:46:08.412: E/AndroidRuntime(19472):    at android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:247)
    07-28 00:46:08.412: E/AndroidRuntime(19472): Caused by: java.lang.NullPointerException
    07-28 00:46:08.412: E/AndroidRuntime(19472):    at net.fortuna.ical4j.util.ResourceLoader.getResourceAsStream(ResourceLoader.java:77)
    07-28 00:46:08.412: E/AndroidRuntime(19472):    at net.fortuna.ical4j.model.TimeZoneRegistryImpl.<clinit>(TimeZoneRegistryImpl.java:76)
    07-28 00:46:08.412: E/AndroidRuntime(19472):    ... 4 more
    

    I'm stumped as to what is wrong or what I can do to fix the problem, I've tried google and this forum but have not found anything to help me. Is there anything I can do to fix this issue?

    I have also added an ical4j.properties file to the root of my src directory but I get a message saying that it cant find it (which can also be seen above). I'd also be delighted if you could help me fix this too.

    Thanks.

    Is mise le meas,
    Ian

     
  • Ben Fortuna

    Ben Fortuna - 2012-07-31

    Hi Ian,

    I suspect both of these issues are related, as it seems resources are not being loaded correctly from the classpath. Here is the static code in TimeZoneRegistryImpl that is most likely the cause of the ExceptionInInitializerError:

    static {
              try {
                  ALIASES.load(ResourceLoader.getResourceAsStream("net/fortuna/ical4j/model/tz.alias"));
              }
              catch (IOException ioe) {
                  LogFactory.getLog(TimeZoneRegistryImpl.class).warn(
                          "Error loading timezone aliases: " + ioe.getMessage());
              }
          }
    

    I am not sure if anything changed recently on Android, but I have run some simple tests with 2.1 and it worked ok. Make sure you are including resources in the final APK being generated, otherwise I will try to test it when I get some time.

    regards,
    ben

     
  • Anonymous - 2012-08-14

    I have the same problem in Android.

    The call works fine if I do it from an Activity, but when I run it from a Service this happens.

     
  • Anonymous - 2012-08-14

    Oh and I also get this error right before it crashes:

    I/Configurator(19472): ical4j.properties not found.

    I think it may be the cause.

    Where am I supposed to put this file? I've tried almost every folder there is, but it still won't see it.

     
  • Anonymous - 2012-08-14

    Okay, problem solved. It was indeed because it did not see the ical4j.properties file, which should be located in the base of your src/ folder. Additionally you have to restart Eclipse before it will register the file.

     
  • Anonymous - 2012-08-14

    Nevermind. That wasn't it. It sort of worked for a while (not sure what happened, maybe the program just didn't launch properly), but now it's back again.

     
  • Anonymous - 2012-08-14

    The problem is that CalendarBuilder is not thread-safe. That is why it's not going to work in a Service. Is there already a bug report on this?

     
  • pengin

    pengin - 2013-04-23

    Did anyone find a solution or workaround for this?

     
  • pengin

    pengin - 2013-04-23

    Did anyone find a solution or workaround for this?

    Also note I have verified the "tz.alias" file exists in the ical4j jar that fortuna mentions.

     
  • Ben Fortuna

    Ben Fortuna - 2013-04-23

    I haven't had much time to investigate this, however if you want to look at an example of using ical4j in Android there is this:

    http://ical4j.hg.sourceforge.net/hgweb/ical4j/ical4j-android-test/

    I haven't tried this project recently, but it was parsing and loading calendar files last time I checked. Note that this doesn't use Android services tho, so the initial issue here may be related to something I am not aware of.

    regards,
    ben

     
  • nis

    nis - 2013-04-29

    I have the same problem when using a service.
    I tested the following log statements from ical4j-android-test:

    Log.i("Class.getResource", String.valueOf(getClass().getResource("net/fortuna/ical4j/model/tz.alias")));
    Log.i("Class.getResource", String.valueOf(getClass().getResource("/net/fortuna/ical4j/model/tz.alias")));
    Log.i("ClassLoader.getResource", String.valueOf(getClass().getClassLoader().getResource("net/fortuna/ical4j/model/tz.alias")));
    Log.i("ClassLoader.getResource", String.valueOf(getClass().getClassLoader().getResource("/net/fortuna/ical4j/model/tz.alias")));
    

    The statements without a leading slash give a null result, but the ones WITH a leading slash give the correct jar path. So it seems that the leading slash is necessary, but the static block in TimeZoneRegistryImpl doesn't use it.

    Hope that helps.

     
  • nis

    nis - 2013-04-29

    Hi guys. I found fix! The problem seems to be the class ResourceLoader. The following statement failes with a NPE.

    stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(name);
    

    This is because

    Thread.currentThread().getContextClassLoader()
    

    returns null.

    So I tried to set the context class loader as follows

    Thread.currentThread().setContextClassLoader(mContext.getClassLoader());
    

    an it works!

     
  • Parag

    Parag - 2015-09-23

    I am trying to use the jar, but I am missing tz.alias along with all the ics files in my apk (verified using baksmali)? I added the ical4j as a static lib in my Android.mk, but I am missing something which would tell the apk to keep the non-java files that are not specified as resources and/or assets. Or should I define them as assets? Any help would be appreciated.

    Thanks.

     
    Last edit: Parag 2015-09-24

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks