clojureillegalargumentexception

IllegalArgumentException using "proxy" in Clojure


I followed this tutorial to learn clojure (https://www.youtube.com/watch?v=zFPiPBIkAcQ at around 2:26). In the last example, you programme the game "Snake".

(ns ...tests.snake
 (:import
   (java.awt Color Dimension)
   (javax.swing JPanel JFrame Timer JOptionPane)
   (java.awt.event ActionListener KeyListener KeyEvent)))

...

113 (defn game-panel [frame snake apple]
114   (proxy [JPanel ActionListener KeyListener] []
115     ;JPanel
116     (paintComponent [g]
117       (proxy-super paintComponent g)
118       (paint g @apple)
119       (paint g @snake))
120     (getPreferredSize []
121       (Dimension. (* (inc field-width) point-size)
122                   (* (inc field-height) point-size)))
123     ;ActionListener
124    (actionPerformed [e]
125       (update-positions snake apple)
126       (if (lose? @snake)
127         (do
128           (reset-game snake apple)
129           (JOptionPane/showMessageDialog frame "You lose")))
130       (if (win? @snake)
131         (do
132           (reset-game snake apple)
133           (JOptionPane/showMessageDialog "You win")))
134       (.repaint this))
135     (keyPressed [e]
136                 (let [direction (directions (.getKeyCode e))]
137                   (if direction 
138                     (update-direction snake direction))))
139     (keyReleased [e])
140     (keyTyped [e])))

I get an IllegalArgumentException there when using "proxy".

; Syntax error (IllegalArgumentException) compiling new at (c:\[...]\Clojure_Project\tests\snake.clj:114:3).
; Unable to resolve classname: ...tests.snake.proxy$javax.swing.JPanel$ActionListener$KeyListener$1b88ffec

I thought at first it might be related to the fact that I am passing multiple arguments, but that doesn't seem to be the problem.

I use VisualStudioCode and the "Getting Starting REPL" from Calva (because I don't know how to connect another one).

I don't know, did I forget to install something or import something? I tried to look at the code of "proxy", but due to the fact that I'm not really familiar with the programming language yet, it didn't help me much.

my code: https://github.com/shadowprincess/clojure-learning


Solution

  • When looking at your question initially, I thought that your ...tests.snake namespace was just something you elided and not the actual namespace name. But given your repo, seems like it's the real namespace name that you're using.

    That's invalid - you can't start a namespace with .. Rename it to tests.snake and the error will go away.

    Unfortunately, your code in the repo still won't work because there are many other errors, but they should be easy for you to figure out on your own. And as a general advice - don't run your whole project by sending separate forms into REPL. Learn how to launch it with a single command - it'll induce good practices that will be useful even when using REPL.