IllegalArgumentException 在 Clojure 中使用"proxy"



我遵循本教程学习clojure(https://www.youtube.com/watch?v=zFPiPBIkAcQ2点26分左右(。在最后一个例子中,您对游戏";"蛇";。

(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])))

当使用";代理";。

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

起初我认为这可能与我传递多个论点有关,但这似乎不是问题所在。

我使用VisualStudioCode和;"开始REPL";来自卡尔瓦(因为我不知道如何连接另一个(。

我不知道,我是忘了安装什么还是导入什么了?我试着查看";"代理";,但由于我还不太熟悉编程语言,这对我没有太大帮助。

我的代码:https://github.com/shadowprincess/clojure-learning

在最初查看您的问题时,我认为您的...tests.snake命名空间只是您忽略的东西,而不是实际的命名空间名称。但考虑到您的repo,它似乎是您正在使用的真实名称空间名称。

这是无效的-不能用.启动命名空间。将其重命名为tests.snake,错误就会消失。

不幸的是,你在回购中的代码仍然无法工作,因为还有很多其他错误,但你应该很容易自己弄清楚。一般建议是,不要通过向REPL发送单独的表单来运行整个项目。学习如何用一个命令启动它——它将引入良好的实践,即使在使用REPL时也是有用的。

最新更新