You could call (import) directly after you've initialised the Gate class: (gate-init "foo") (import gate.Factory) ; use Factory class as required
Cheers, Stuart On 31 August 2010 01:01, zm <zygiman...@medelis.lt> wrote: > > Initialization exception can be avoided if Factory class is > initialized indirectly: > > (let [factory (.newInstance (Class/forName "gate.Factory"))] ...) > > The problem is that Factory can only be initialized (its static > fields) after Gate.init was called. But clojure reader (or what it is) > initializes all the classes mentioned in the namespace. Thus Factory > gets created before cojure function calls which do Gate/init. > > Is this workaround ok? Or are there better ways to solve it? > > On Aug 30, 2:39 pm, zm <zygiman...@medelis.lt> wrote: > > Indeed if exception is thrown in static initializer block then clojure > > import throws exception as well. > > > > The following class will cause this: > > > > package aaa; > > public class Test { > > static{ > > Object o = null; > > o.toString(); > > } > > > > } > > > > Then in clojure: > > > > (ns x (:import (aaa Test)) > > > > Results in: > > > > Exception in thread "main" java.lang.ExceptionInInitializerError > > (core.clj:1) > > > > Why does this happen in clojure? If you do the same in java, import > > aaa.Test, then nothing happens. NLP will be thrown when you actualy > > try to initialize the class. > > > > On Aug 30, 6:12 am, Stuart Campbell <stu...@harto.org> wrote: > > > > > > > > > Hello, > > > > > I don't know this library specifically, but the NPE is probably > occurring in > > > a static initialisation block. I believe static initialisation occurs > when > > > the class is first loaded. > > > > > Regards, > > > Stuart > > > > > On 30 August 2010 06:42, zm <zygiman...@medelis.lt> wrote: > > > > > > I am using GATE java libs in my clojure code and behaviour of the > > > > application changes after Java class import. I don't even have to > > > > initialize it. > > > > > > This runs fine (a bit shorter version than it is): > > > > > > (ns gate > > > > (:import > > > > (gate Gate) > > > > (java.io File))) > > > > > > (defn gate-init > > > > [gate-home] > > > > (Gate/setGateHome (File. gate-home)) > > > > (Gate/init))) > > > > > > Now if I import gate.Factory class, like this (gate Gate Factory), I > > > > get the exception: > > > > > > Caused by: java.lang.NullPointerException > > > > at gate.Factory.createResource(Factory.java:154) > > > > > > How can import of a class cause this? > > > > > > -- > > > > You received this message because you are subscribed to the Google > > > > Groups "Clojure" group. > > > > To post to this group, send email to clojure@googlegroups.com > > > > Note that posts from new members are moderated - please be patient > with > > > > your first post. > > > > To unsubscribe from this group, send email to > > > > clojure+unsubscr...@googlegroups.com<clojure%2bunsubscr...@googlegroups.com> > <clojure%2bunsubscr...@googlegroups.com<clojure%252bunsubscr...@googlegroups.com>> > > > > For more options, visit this group at > > > >http://groups.google.com/group/clojure?hl=en > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com<clojure%2bunsubscr...@googlegroups.com> > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en