user561236 user561236 - 8 months ago 49
Java Question

java.swing can not be cast to clojure Ifn


Ludum Dare 36
I decided to try a text based adventure game in coljure. It works, but I am getting a non-fatal error :

Exception in thread "main" java.lang.ClassCastException:
seesaw.core.proxy$javax.swing.JPanel$Tag$fd407141 cannot be cast to

(ns ludumdare36.core
(:gen-class :main true)
(:use seesaw.core))

(def story [
"Of all the most famous living rooms Transned's was the most famous"

(def mainWindow (frame :title "Hello" :content "" :on-close :exit))

(defn draw
[items & args] (
(def mainWidget (vertical-panel :items items) )
(config! mainWidget :size [640 :by 480])
(config! mainWindow :content mainWidget)
(invoke-later(-> mainWindow pack! show!))))

(defn writeStory [text index & args]
(let [makeButton (fn mb [index text]
(button :text text :mnemonic \N :halign :center :listen [:action (partial writeStory (get story index) (inc index))]))
makeStoryNode (fn ms [text index]
(vector text (makeButton (inc index) "Yes") (makeButton (+ index 2 ) "No")))
(draw (makeStoryNode text index))))

(defn -main
[& args]
(writeStory (get story 0) 0))

The Ifn error is fairly well documented on stack, but I am not sure which function is causing the issue. Also not sure on the quality of my code. So feel free to post comments etc. How can I refactor to get rid of the Ifn error? What do I not understand?


Starting on line 21 you have extra set of parens around the function body; it would be a potential cause for clojure to think you want to call up a function that's being returned by the (def...) exp. But that results in a Swing object that is not callable as is.