views:

93

answers:

2

Hi!

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.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!

+1  A: 

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

Michael Kohl
Not really, I can't evaluate the final classes in any function, including `show` and `import-static`. :(
konr
Sorry, as I said, I'm not overly familiar with the Java-side of things. There seems to be some talk going on in this IRC transcript http://clojure-log.n01se.net/date/2010-07-03.html, search for the NoClassDefFoundError and start reading a bit above that. If this doesn't help, IRC is probably a good place to go ask for help.
Michael Kohl
+3  A: 

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.

Brian Carper