swingclojurecompiler-errorsleiningenrepaintmanager

Using Swing in Clojure - Compiler Exception: could not initialise RepaintManager


I've just started trying to create a UI with Clojure using Swing. But I am getting a CompilerException when trying to load it. I have been following this tutorial 'https://stuartsierra.com/2010/01/02/swing-into-actions-with-clojure'.

I am using IntelliJ IDEA Community with Cursive, using Leiningen and Clojure 1.8 and I'm on Linux Mint 19.1 (if that even matters).

My code:

(defn say-hello []
  (JOptionPane/showMessageDialog
    nil "Hello, World!" "Greeting" JOptionPane/INFORMATION_MESSAGE))

(def act (proxy [ActionListener] []
           (actionPerformed [event] (say-hello))))

(def button (doto (JButton. "Click Me!")
              (.addActionListener act)))

(def panel (doto (JPanel.)
             (.add button)))
(def frame (doto (JFrame. "Hello Frame")
             (.setSize 800 800)
             (.setContentPane panel)
             (.setVisible true)))


(def frame (doto (JFrame. "SportSeer")
             (.setSize 800 800)
             (.setVisible true)))

When ran through nREPL I get:

Loading src/sportseer_client/core.clj... 
CompilerException java.lang.NoClassDefFoundError: Could not initialize class javax.swing.RepaintManager, compiling:(core.clj:12:13) 

Edit: Also, when I restart the REPL and load the file for the first time I get this error:

Loading src/sportseer_client/core.clj... 
CompilerException java.awt.AWTError: Assistive Technology not found: org.GNOME.Accessibility.AtkWrapper, compiling:(core.clj:12:13)

Somehow I have had this example work when messing about within the repl alone, and then afterwards being able to load from a file without any problems. No idea what I done differently except for using the other import function:

(import '(javax.swing JOptionPan JButton JFrame JPanel))

but I can no longer replicate this and get this to work.

Any help in pointing me in the right direction to fix this will be greatly appreciated.


Solution

  • I've seen the CompilerException java.awt.AWTError: Assistive Technology not found when trying to run a PDF generation code (which uses AWT) on a linux server with OpenJDK 8. After a switch to JDK 10/11 the error went away.

    There might be lots of "fun" issues with graphics-related code, especially when you run on a server without a proper display.

    I know we get the CompilerException java.lang.NoClassDefFoundError: Could not initialize class error in that case when running the Alpine Linux distribution in docker - although it was a different one: java.lang.NoClassDefFoundError: Could not initialize class sun.awt.image.IntegerInterleavedRaster

    In our case, it was ultimately related to the fontconfig package. For the Apline Linux following helped: apk --update add ttf-dejavu

    More about this problem: