1

I'm trying to write a JavaFX app in Clojure. As a simple test, I wanted to try to just launch a Hello World. To extend Application, I decided to try using proxy instead of :gen-class. I wanted to be able to create a bare-bones function that creates an Application, instead of requiring me to write the boilerplate every time.

The simple example I came up with was:

(let [^Application app
      (proxy [Application] []
        (start [self stage] (println "Hello World")))]

  (Application/launch ^Class (.getClass app)
                      (into-array String [])))

The problem is, this causes an UnsupportedOperationException:

UnsupportedOperationException start chat.graphics_tests.javafx_wrapper.proxy$javafx.application.Application$ff19274a.start (:-1)

It seems like it can't find the start method that I implemented. My first thought was that the arguments to start were wrong. They seem correct though. The first argument it receives is "this", then the primary stage. I tried different numbers of arguments though, and I still get the same error. According to the docs:

If a method fn is not provided for an interface method, an UnsupportedOperationException will be thrown should it be called.

Which further my this suspicion.

The errors quite vague. Does anyone see what the problem is?

Carcigenicate
  • 43,494
  • 9
  • 68
  • 117
  • I just read that `proxy` can't be used here since `Application/launch` requires a named class. Guess I'm using `:gen-class`. – Carcigenicate Sep 26 '17 at 20:51

2 Answers2

0

When writing proxy class definitions in Clojure you do not need the explicit self parameter in the method signature. The current instance will be implicitly bound to this which you will be able to use inside the methods.

Therefore your proxy call should look like this:

  (proxy [Application] []
    (start [stage] (println "Hello World")))
erdos
  • 3,135
  • 2
  • 16
  • 27
  • Nope, same error. As I said, I had tried many different combinations of arguments. And, as I mentioned in the comment under my answer, I read afterward that `proxy` can't be used here. I decided to leave the question up in case anyone else is trying to use `proxy`. I suspect they'll get the same error message. – Carcigenicate Sep 27 '17 at 11:37
0

This appears to be because Application/launch requires a named class, which proxy doesn't create. (see the comment at the bottom of the answer. I'm trusting @Sam here).

I ended up caving and using :gen-class, and got it working after some fiddling.

Carcigenicate
  • 43,494
  • 9
  • 68
  • 117