I keep getting the following error, its most likely something obvious but i'm rather new to this. Any help would be appreciated. I'm quite sure there error is in this section of the code.
(b/defcomponent client {:bounce/deps #{config/value}}
(log/info "Connecting to Discord")
(let [token (get-in config/value [:discord :token])
client (if token
(.. (ClientBuilder.)
(withToken token)
login)
(throw (Error. "Discord token not found, please set {:discord {:token \"...\"}} in `config/config.edn`.")))]
Had a look through where i believe the error is, cant seem to figure it out though.
(ns snowball.discord
(:require [clojure.string :as str]
[clojure.core.async :as a]
[bounce.system :as b]
[taoensso.timbre :as log]
[camel-snake-kebab.core :as csk]
[snowball.config :as config]
[snowball.util :as util])
(:import [sx.blah.discord.api ClientBuilder]
[sx.blah.discord.util.audio AudioPlayer]
[sx.blah.discord.handle.audio IAudioReceiver]
[sx.blah.discord.api.events IListener]))
(defn event->keyword [c]
(-> (str c)
(str/split #"\.")
(last)
(str/replace #"Event.*$" "")
(csk/->kebab-case-keyword)))
(defmulti handle-event! (fn [c] (event->keyword c)))
(defmethod handle-event! :default [_] nil)
(declare client)
(defn ready? []
(some-> client .isReady))
(defn poll-until-ready []
(let [poll-ms (get-in config/value [:discord :poll-ms])]
(log/info "Connected, waiting until ready")
(util/poll-while poll-ms (complement ready?) #(log/info "Not ready, sleeping for" (str poll-ms "ms")))
(log/info "Ready")))
(defn channels []
(some-> client .getVoiceChannels seq))
(defn channel-users [channel]
(some-> channel .getConnectedUsers seq))
(defn current-channel []
(some-> client .getConnectedVoiceChannels seq first))
(defn ->name [entity]
(some-> entity .getName))
(defn ->id [entity]
(some-> entity .getLongID))
(defn leave! [channel]
(when channel
(log/info "Leaving" (->name channel))
(.leave channel)))
(defn join! [channel]
(when channel
(log/info "Joining" (->name channel))
(.join channel)))
(defn bot? [user]
(some-> user .isBot))
(defn muted? [user]
(when user
(let [voice-state (first (.. user getVoiceStates values))]
(or (.isMuted voice-state)
(.isSelfMuted voice-state)
(.isSuppressed voice-state)))))
(defn can-speak? [user]
(not (or (bot? user) (muted? user))))
(defn has-speaking-users? [channel]
(->> (channel-users channel)
(filter can-speak?)
(seq)
(boolean)))
(defn default-guild []
(some-> client .getGuilds seq first))
(defn guild-users []
(some-> (default-guild) .getUsers))
(defn guild-text-channels []
(some-> (default-guild) .getChannels))
(defn guild-voice-channels []
(some-> (default-guild) .getVoiceChannels))
(defn move-user-to-voice-channel [user channel]
(when (and user channel)
(try
(.moveToVoiceChannel user channel)
(catch Exception e
(log/warn "Tried to move a user to a voice channel that isn't connected to voice already")))))
(defn play! [audio]
(when audio
(when-let [guild (default-guild)]
(doto (AudioPlayer/getAudioPlayerForGuild guild)
(.clear)
(.queue audio)))))
(defn send! [channel-id message]
(when-let [channel (.getChannelByID (default-guild) channel-id)]
(log/info "Sending message to" channel-id "-" message)
(.sendMessage channel message)))
(defmethod handle-event! :reconnect-success [_]
(log/info "Reconnection detected, leaving any existing voice channels to avoid weird state")
(poll-until-ready)
(when-let [channel (current-channel)]
(leave! channel)))
(defn audio-manager []
(some-> (default-guild) .getAudioManager))
(defrecord AudioEvent [audio user])
(defn subscribe-audio! [f]
(let [sub! (atom nil)
closed?! (atom false)
sub-chan (a/go-loop []
(when-not #closed?!
(a/<! (a/timeout (get-in config/value [:discord :poll-ms])))
(if-let [am (audio-manager)]
(try
(let [sub (reify IAudioReceiver
(receive [_ audio user _ _]
(try
(when-not (bot? user)
(f (AudioEvent. audio user)))
(catch Exception e
(log/error "Caught error while passing audio event to subscription handler" e)))))]
(reset! sub! sub)
(log/info "Audio manager exists, subscribing to audio")
(.subscribeReceiver am sub))
(catch Exception e
(log/error "Caught error while setting up audio subscription" e)))
(recur))))]
(fn []
(when-let [sub #sub!]
(reset! closed?! true)
(a/close! sub-chan)
(.unsubscribeReceiver (audio-manager) sub)))))
(b/defcomponent client {:bounce/deps #{config/value}}
(log/info "Connecting to Discord")
(let [token (get-in config/value [:discord :token])
client (if token
(.. (ClientBuilder.)
(withToken token)
login)
(throw (Error. "Discord token not found, please set {:discord {:token \"...\"}} in `config/config.edn`.")))]
(.registerListener
(.getDispatcher client)
(reify IListener
(handle [_ event]
(handle-event! event))))
(with-redefs [client client]
(poll-until-ready))
(b/with-stop client
(log/info "Shutting down Discord connection")
(.logout client))))
(b/defcomponent audio-chan {:bounce/deps #{client}}
(log/info "Starting audio channel from subscription")
(let [audio-chan (a/chan (a/sliding-buffer 100))
sub (subscribe-audio!
(fn [event]
(a/go
(a/put! audio-chan event))))]
(b/with-stop audio-chan
(log/info "Closing audio channel and unsubscribing")
(sub)
(a/close! audio-chan))))
Below is the error i am getting
> make
> ./run.sh
> 19-05-25 19:05:45 localhost INFO [snowball.main:6] - Starting components...
> 19-05-25 19:05:47 localhost INFO [snowball.config:16] - Loading base config from config.base.edn and user config from
> config/config.edn
> 19-05-25 19:05:47 localhost INFO [snowball.discord:150] - Connecting to Discord
> Exception in thread "main" java.lang.ClassCastException: class clojure.lang.Symbol cannot be cast to class java.lang.String
> (clojure.lang.Symbol is in unnamed module of loader 'app';
> java.lang.String is in module java.base of loader 'bootstrap')
> at snowball.discord$eval12963$start_client__12964.invoke(discord.clj:152)
> at clojure.lang.AFn.applyToHelper(AFn.java:152)
> at clojure.lang.AFn.applyTo(AFn.java:144)
> at clojure.core$apply.invokeStatic(core.clj:665)
> at clojure.core$apply.invoke(core.clj:660)
> at bounce.system$start_system$fn__479$fn__480.invoke(system.clj:68)
> at bounce.system$start_system$fn__479$fn__480$fn__481.invoke(system.clj:71)
> at clojure.lang.AFn.applyToHelper(AFn.java:152)
> at clojure.lang.AFn.applyTo(AFn.java:144)
> at clojure.core$apply.invokeStatic(core.clj:665)
> at clojure.core$with_bindings_STAR_.invokeStatic(core.clj:1973)
> at clojure.core$with_bindings_STAR_.doInvoke(core.clj:1973)
> at clojure.lang.RestFn.invoke(RestFn.java:425)
> at bounce.system$start_system$fn__479$fn__480.invoke(system.clj:69)
> at bounce.system$start_system.invokeStatic(system.clj:80)
> at bounce.system$start_system.invoke(system.clj:59)
> at bounce.system$start_BANG_.invokeStatic(system.clj:122)
> at bounce.system$start_BANG_.invoke(system.clj:112)
> at snowball.main$_main.invokeStatic(main.clj:13)
> at snowball.main$_main.invoke(main.clj:5)
> at clojure.lang.AFn.applyToHelper(AFn.java:152)
> at clojure.lang.AFn.applyTo(AFn.java:144)
> at clojure.lang.Var.applyTo(Var.java:705)
> at clojure.core$apply.invokeStatic(core.clj:665)
> at clojure.main$main_opt.invokeStatic(main.clj:491)
> at clojure.main$main_opt.invoke(main.clj:487)
> at clojure.main$main.invokeStatic(main.clj:598)
> at clojure.main$main.doInvoke(main.clj:561)
> at clojure.lang.RestFn.applyTo(RestFn.java:137)
> at clojure.lang.Var.applyTo(Var.java:705)
> at clojure.main.main(main.java:37)
> Makefile:12: recipe for target 'run' failed
> make: *** [run] Error 1
From this bit:
> 19-05-25 19:05:47 localhost INFO [snowball.discord:150] - Connecting to Discord
> Exception in thread "main" java.lang.ClassCastException: class clojure.lang.Symbol cannot be cast to class java.lang.String
It looks like the expression (get-in config/value [:discord :token]) in line 152 is returning a symbol (a clojure.lang.Symbol) instead of a String, and that is causing a ClassCastException to be thrown when building the Client class.
I guess what's going on is that you are reading the configuration from an external file or some other source and your token is not properly quoted, so it's being resolved as a Symbol ("a variable name") instead of a String.
Related
I am using [org.clojure/clojure "1.10.1"],[org.clojure/core.async "1.2.603"] and the latest Amazon Corretto 11 JVM if there was anything to do with them.
The following code is a simplified version of the code used in production and it does cause memory leak. I have no idea why that happened but suspect it might due to sub/unsub of channels. Can anyone help point out where my code may go wrong or how I can fix the memory leak?
(ns test-gc.core
(:require [clojure.core.async :as a :refer [chan put! close! <! go >! go-loop timeout]])
(:import [java.util UUID]))
(def global-msg-ch (chan (a/sliding-buffer 200)))
(def global-msg-pub (a/pub global-msg-ch :id))
(defn io-promise []
(let [id (UUID/randomUUID)
ch (chan)]
(a/sub global-msg-pub id ch)
[id (go
(let [x (<! ch)]
(a/unsub global-msg-pub id ch)
(:data x)))]))
(defn -main []
(go-loop []
(<! (timeout 1))
(let [[pid pch] (io-promise)
cmd {:id pid
:data (rand-int 1E5)}]
(>! global-msg-ch cmd)
(println (<! pch)))
(recur))
(while true
(Thread/yield)))
A quick heap dump gives the following statistics for example:
Class by number of instances
java.util.LinkedList 5,157,128 (14.4%)
java.util.concurrent.atomic.AtomicReference 3,698,382 (10.3%)
clojure.lang.Atom 3,094,279 (8.6%)
...
Class by size of instances
java.lang.Object[] 210,061,752 B (13.8%)
java.util.LinkedList 206,285,120 B (13.6%)
clojure.lang.Atom 148,525,392 B (9.8%)
clojure.core.async.impl.channels.ManyToManyChannel 132,022,336 B (8.7%)
...
I finally figured out why. By looking at the source code, we get the following segment:
(defn pub
"Creates and returns a pub(lication) of the supplied channel, ..."
...
(let [mults (atom {}) ;;topic->mult
ensure-mult (fn [topic]
(or (get #mults topic)
(get (swap! mults
#(if (% topic) % (assoc % topic (mult (chan (buf-fn topic))))))
topic)))
p (reify
Mux
(muxch* [_] ch)
Pub
(sub* [p topic ch close?]
(let [m (ensure-mult topic)]
(tap m ch close?)))
(unsub* [p topic ch]
(when-let [m (get #mults topic)]
(untap m ch)))
(unsub-all* [_] (reset! mults {}))
(unsub-all* [_ topic] (swap! mults dissoc topic)))]
...
p)))
We can see mults stores all topic hence shall increase monotonically if we do not clear it. We may add something like (a/unsub-all* global-msg-pub pid) to fix that.
I am getting the following stacktrace when running the command: lein run "this is the other different thing" "this,different,other"
Stacktrace
Exception in thread "main" java.lang.NullPointerException, compiling:(/private/var/folders/y8/6lt_81xn47d4n2k641z52rg00000gn/T/form-init8328218573408236617.clj:1:125)
at clojure.lang.Compiler.load(Compiler.java:7391)
at clojure.lang.Compiler.loadFile(Compiler.java:7317)
at clojure.main$load_script.invokeStatic(main.clj:275)
at clojure.main$init_opt.invokeStatic(main.clj:277)
at clojure.main$init_opt.invoke(main.clj:277)
at clojure.main$initialize.invokeStatic(main.clj:308)
at clojure.main$null_opt.invokeStatic(main.clj:342)
at clojure.main$null_opt.invoke(main.clj:339)
at clojure.main$main.invokeStatic(main.clj:421)
at clojure.main$main.doInvoke(main.clj:384)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.lang.Var.invoke(Var.java:383)
at clojure.lang.AFn.applyToHelper(AFn.java:156)
at clojure.lang.Var.applyTo(Var.java:700)
at clojure.main.main(main.java:37)
Caused by: java.lang.NullPointerException
at clojure.string$replace.invokeStatic(string.clj:101)
at clojure.string$replace.invoke(string.clj:75)
at redact.core$redact_doc.invokeStatic(core.clj:12)
at redact.core$redact_doc.invoke(core.clj:7)
at redact.core$_main.invokeStatic(core.clj:54)
at redact.core$_main.doInvoke(core.clj:50)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.lang.Var.invoke(Var.java:383)
at user$eval5.invokeStatic(form-init8328218573408236617.clj:1)
at user$eval5.invoke(form-init8328218573408236617.clj:1)
at clojure.lang.Compiler.eval(Compiler.java:6927)
at clojure.lang.Compiler.eval(Compiler.java:6917)
at clojure.lang.Compiler.load(Compiler.java:7379)
... 14 more
And here is my code:
(ns redact.core
(:gen-class)
(:require [clojure.java.io :as io]
[clojure.string :as str]
))
(defn redact-doc
;; Reads the file line by line and redacts all the matched words
([target stoplist]
(if (empty? stoplist)
(str/trim target)
(redact-doc (str/replace target (re-pattern (str "\\s(" (first stoplist) ")(\\s|$)")) " REDACTED ") (rest stoplist))))
)
(defn get-target-text
;; Takes a vector of args and returns a String of a text file or and sentances
([args] (get-target-text args ""))
([args result]
(if (empty? args)
result
(get-target-text (rest args) (if (boolean (re-find #"(.+\.[^csv\s])" (first args)))
(str result (slurp (first args)))
(if (not (boolean (re-find #"(.+\.csv|.+,.+)" (first args))))
(if (boolean (re-find #"\s" (str/trim (first args))))
(str result (first args) " ")))))))
)
(defn read-csv
;; Takes in a filename and returns a vector of the csv values
[file-name]
(str/split (with-open [rdr (io/reader file-name)]
(doall (reduce str (line-seq rdr)))) #","))
(defn gen-stoplist
;; Generates the stoplist for words to be redacted
([args] (gen-stoplist args []))
([args stoplist]
(if (empty? args)
stoplist
(gen-stoplist (rest args) (if (boolean (re-find #"(.+\.csv)" (first args)))
(into [] (concat stoplist (read-csv (first args))))
(if (boolean (re-find #"(.+\..[^csv\s])" (first args)))
stoplist
(if (boolean (re-find #"(.*,.*)" (first args)))
(into [] (concat stoplist (str/split (first args) #",")))
(if (boolean (re-find #"(\s)" (str/trim (first args))))
stoplist
(into [] (concat stoplist [(first args)] ))))))))))
(defn -main
([& args]
(def stoplist (gen-stoplist args))
(def target-text (get-target-text args))
(println (redact-doc target-text stoplist)))
)
I have been staring at this trying to figure out what is causing the issue. I have tested all of the methods independently on the REPL and they all seem to work but the (-main) method is throwing a null pointer exception on the str/replace call....just not sure why. Any help you can give is much appreciated. Thanks!
There is a fair bit about your code which is not really correct. My guess is
that our getting that call because your calling a function which is expecting a
value and is getting a nil passed in - my guess would be one of the string
functions.
your function definitions are not quite right. If your function only has a
single 'signature' then you don't need the additional brackets. You should also
use let bindings inside rather than def. e.g.
(defn -main
[& args]
(let [stoplist (gen-stoplist args)
target-text (get-target-text args))]
(println (redact-doc target-text stoplist)))
Your code is not passing what you think to gen-stoplist or get-target-text. I
suspect the null pointer is because of the call to str/trim being passed a nil
rather than a string.
My suggestion would be to open a repl and interact with it using some println in
your functions to look at what is getting parsed in.
I am trying to show a graph on riemann-dashboard using query
"pingDelay > 0" .
I already have indexed my data using following code
(let [index (index)]
(defn write-dht-metric [e]
(let [dhtstate (re-find #"dht_status: health\.(\S+), msg count (\d+) \((\d+) bytes\).*peak \{ping = (\d+)" (:pgmsg e))]
(if (not= dhtstate nil)
(do
(prn "RESULT>" dhtstate)
(index {:host "dht-info"
:service (:service e)
:time (unix-time)
:dhtStatus (get dhtstate 1)
:msgCount (get dhtstate 2)
:pingDelay (get dhtstate 3)}
)
)
)
)
)
)
However, I am not getting anything on graph. Earlier, I thought that perhaps its because my "pingDelay" is in string "12345", so, i also tried ":pingDelay #(Long. (get dhtstate 3))" without any success.
Can anyone please help me about what I must do to make it work?
Regards
defining top level forms in function calls is a little odd. It works only because defining a var returns that var to the calling form. It's more typical to write it like:
(defn write-dht-metric [e]
(let [dhtstate (re-find #"dht_status: health\.(\S+), msg count (\d+) \((\d+) bytes\).*peak \{ping = (\d+)" (:pgmsg e))]
(if (not= dhtstate nil)
(do
(prn "RESULT>" dhtstate)
(index {:host "dht-info"
:service (:service e)
:time (unix-time)
:dhtStatus (get dhtstate 1)
:msgCount (get dhtstate 2)
:pingDelay (get dhtstate 3)})))))
(let [index (index)]
(streams
write-dht-metric))
there are several other ways of writing it:
(defn write-dht-metric [e]
(let [dhstate (:dhstate e)]
(prn "RESULT>" dhtstate)
(index {:host "dht-info"
:service (:service e)
:time (unix-time)
:dhtStatus (get dhtstate 1)
:msgCount (get dhtstate 2)
:pingDelay (get dhtstate 3)})))
(let [index (index)]
(streams
(with :dhstate (re-find #"dht_status: health\.(\S+), msg count (\d+) \((\d+) bytes\).*peak \{ping = (\d+)" (:pgmsg event))
(when :dhstate
write-dht-metric)))
It turned out that I had to write value of my pingDelay in ":metric field". It starts working now.
I'm trying to validate the protocol of an instance of defrecord that I generate dynamically using clojure.core/extend
Below You can see that satisfies returns true and (s/validate (s/protocol ...)) doesn't throw exception, but if I run s/with-fn-validation I get a "(not (satisfies? protocol ..... " schema exception although inside this body I keep getting the same true result for (satisfies? protocol x)
(ns wrapper.issue
(:require [schema.core :as s]))
(defprotocol Welcome
(greetings [e] )
(say_bye [e a b])
)
(s/defn greetings+ :- s/Str
[component :- (s/protocol Welcome)]
(greetings component))
(defrecord Example []
Welcome
(greetings [this] "my example greeting!")
(say_bye [this a b] (str "saying good bye from " a " to " b))
)
(defrecord MoreSimpleWrapper [e])
(extend MoreSimpleWrapper
Welcome
{:greetings (fn [this]
(str "wrapping!! " (greetings (:e this)))
)
:say_bye (fn [this a b]
(str "good bye !"))})
(println (satisfies? Welcome (MoreSimpleWrapper. (Example.))))
;;=>true
(println (s/validate (s/protocol Welcome) (MoreSimpleWrapper. (Example.))))
;;=>#wrapper.issue.MoreSimpleWrapper{:e #wrapper.issue.Example{}}
(s/with-fn-validation
(println (satisfies? Welcome (MoreSimpleWrapper. (Example.))))
;;=>true
(println (s/validate (s/protocol Welcome) (MoreSimpleWrapper. (Example.))))
;;=>#wrapper.issue.MoreSimpleWrapper{:e #wrapper.issue.Example{}}
)
(s/with-fn-validation
(greetings+ (MoreSimpleWrapper. (Example.))))
;;=>CompilerException clojure.lang.ExceptionInfo: Input to greetings+ does not match schema: [(named (not (satisfies? Welcome a-wrapper.issue.MoreSimpleWrapper)) component)] {:schema [#schema.core.One{:schema (protocol Welcome), :optional? false, :name component}], :value [#wrapper.issue.MoreSimpleWrapper{:e #wrapper.issue.Example{}}], :error [(named (not (satisfies? Welcome a-wrapper.issue.MoreSimpleWrapper)) component)]}, compiling:(/Users/tangrammer/git/olney/wrapper/src/wrapper/issue.clj:39:69)
Here also a gist with the code
It was a schema bug :)
now fixed in snapshot-0.3.2
https://github.com/Prismatic/schema/issues/164
this program opens a file read it into a list
then asks the user to enter the word from the list one at a time
but I get an error right after it speaks
(ns EKS.Core)
(use '[speech-synthesis.say :as say])
(use '[clojure.java.shell :only [sh]])
(use 'seesaw.core)
(use 'seesaw.dev)
(use 'seesaw.chooser)
(use 'clojure.java.io)
(import 'java.io.File)
(native!)
(defn festival [x](sh "sh" "-c" (str "echo " x " | festival --tts")))
(defn espeak [x] (sh "espeak" x))
(defn mac-say[x] (sh "say" x))
(defn check-if-installed[x] (:exit(sh "sh" "-c" (str "command -v " x " >/dev/null 2>&1 || { echo >&2 \"\"; exit 1; }"))))
(defn env
"Returns the system property for user.<key>"
[key]
(System/getProperty (str "user." key)))
(defn get-lines [fname]
(with-open [r (reader fname)]
(doall (line-seq r))))
(defn engine-check[]
(def engines (conj["Google" ]
(if (= (check-if-installed "festival") 0) "Festival" )
(if (= (check-if-installed "espeak") 0) "ESpeak" )
(if (= (check-if-installed "say") 0) "Say" )))(remove nil? engines))
(engine-check)
(def ListDir (str (env "home") ))
(def speak say)
(defn setup-list[ file](
(def ListEntry (remove #{""} (get-lines (.getAbsolutePath file))))
(speak (str "Enter the word " (first ListEntry)))
(.getAbsolutePath file)
(def current 0)))
(def Open-Action (action :handler (fn [e] (choose-file :type :open :selection-mode :files-only :dir ListDir :success-fn (fn [fc file](setup-list file))))
:name "Open"
:key "menu O"
:tip "Open list"))
(def entry-text(text :id :entry :text "" ))
(defn check-word[] ((if (= (text entry-text) (nth ListEntry current))(speak "correct")(speak "incorrect"))(def current (+ current 1))(speak (str "Enter the word " (nth ListEntry current)))))
(def Main-Panel(grid-panel :vgap 7 :hgap 20 :border "Main" :items[ (top-bottom-split entry-text
(left-right-split (grid-panel :vgap 7 :items[(label :text "Correct: 0") (label :text "Incorrect: 0")]) (grid-panel :vgap 7 :items[(button :text "Next"
:mnemonic \N
:listen [:action (fn [e] (check-word))])
(button :text "Repeat!"
:mnemonic \\
:listen [:action (fn[e] (speak(nth ListEntry current)))])
]) :divider-location 1/3 )
:divider-location 1/3 )]))
(def Main-Window(frame :title "??????", :on-close :exit, :size[425 :by 172]:menubar(menubar :items[(menu :text "File" :items [Open-Action ])]) :content Main-Panel ))
(show! Main-Window)
this is the error message I get when opening a file
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: clojure.lang.LazySeq cannot be cast to clojure.lang.IFn
at clojure.lang.Var.fn(Var.java:378)
at clojure.lang.Var.invoke(Var.java:409)
at EKS.Core$setup_list.invoke(NO_SOURCE_FILE:38)
at EKS.Core$fn__5794$fn__5795.invoke(NO_SOURCE_FILE:42)
at seesaw.chooser$choose_file.doInvoke(chooser.clj:173)
at clojure.lang.RestFn.invoke(RestFn.java:619)
at EKS.Core$fn__5794.invoke(NO_SOURCE_FILE:42)
at seesaw.action$action$fn__1218.invoke(action.clj:90)
at seesaw.action.proxy$javax.swing.AbstractAction$0.actionPerformed(Unknown Source)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:833)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:877)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:713)
at java.awt.EventQueue.access$000(EventQueue.java:104)
at java.awt.EventQueue$3.run(EventQueue.java:672)
at java.awt.EventQueue$3.run(EventQueue.java:670)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:686)
at java.awt.EventQueue$4.run(EventQueue.java:684)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:683)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)
this is the test file I am using
this
here
word
What I believe is causing the traceback is:
(defn setup-list[ file](
(def ListEntry (remove #{""} (get-lines (.getAbsolutePath file))))
(speak (str "Enter the word " (first ListEntry)))
(.getAbsolutePath file)
(def current 0)))
Notice the paren after [ file]. You're calling def (which is probably not what you mean to do), but the result of that def is a lazy sequence (because of remove) and it being called as a function because of that paren. Unfortunately, it's not clear what you're trying to do with setup-list, otherwise I'd write something more idiomatic for you.
There a few other things you should consider. First, don't use (def ...) inside a function that's really bad form. In this case, I think what you're really after is (let ...):
(defn setup-list [file]
(let [entries (get-lines (.getAbsolutePath file))]
...))
It would also help you to see what's going on if you could keep a little more structure to the code. I think the formatting is letting things like that paren hide, where it may have been more obvious if you had a better style:
(defn setup-list [file]
((def ListEntry ...)
...))
Here, it's little more clear that the def will be used as a function call, which is probably not what you want.
BTW, Clojure has some Library Coding Standards. They've got some good things in there. And Ring is an excellent example to follow for a code base, as is Seesaw.