user561236 user561236 - 2 months ago 15
Java Question

java.swing can not be cast to clojure Ifn

For

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
clojure.lang.IFn,
compiling:(/tmp/form-init2500875452880490300.clj:1:73)


(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"
"two"
"three"
"four"
"five"
"six"
"seven"
"eight"
"nine"
])

(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?

Answer

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.

Comments