Importing final classes
I'm failing to import final classes from a java package. Importing normal classes works fine. For example:
gtk-examples.snooping> (import 'org.gnome.gdk.MouseButton) org.gnome.gdk.MouseButton gtk-examples.snooping> (import 'org.gnome.gdk.ModifierType) ; Evaluation aborted. gtk-examples.snooping>
The last import yields a NoClassDefFoundError. Here is a more complete output:
Could not initialize class org.gnome.gdk.ModifierType [Thrown class java.lang.NoClassDefFoundError] Restarts: 0: [QUIT] Quit to the SLIME top level Backtrace: 0: java.lang.Class.forName0(Native Method) 1: java.lang.Class.forName(Class.java:186) 2: gtk_examples.snooping$eval2063.invoke(NO_SOURCE_FILE:1) 3: clojure.lang.Compiler.eval(Compiler开发者_C百科.java:5424) 4: clojure.lang.Compiler.eval(Compiler.java:5415) 5: clojure.lang.Compiler.eval(Compiler.java:5391) 6: clojure.core$eval.invoke(core.clj:2382) --more--
Any idea of what is going on?
Thanks!
Trying to import org.gnome.gdk.ModifierType
actually gives you a different error first, then gives you the error you're seeing.
user> (import 'org.gnome.gdk.ModifierType)
; Evaluation aborted.
org.freedesktop.bindings.FatalError:
You *must* call Gtk.init() before using anything else in java-gnome!
user> (import 'org.gnome.gdk.ModifierType)
; Evaluation aborted.
java.lang.NoClassDefFoundError: Could not initialize class org.gnome.gdk.ModifierType
Per the docs, org.gnome.gtk.Gtk/init
looks like:
public static void init(String[] args)
So restart the JVM and try this:
user> (org.gnome.gtk.Gtk/init (make-array String 0))
nil
user> (import 'org.gnome.gdk.ModifierType)
org.gnome.gdk.ModifierType
Seems to work.
I'm lacking the Java know-how to give a proper answer, but maybe import-static is what you are looking for?
(import-static class & fields-and-methods)
Imports the named static fields and/or static methods of the class as (private) symbols in the current namespace.
http://clojuredocs.org/v/487
精彩评论