我跟着this tutorial使用Leiningen从Eclipse中的Java调用Clojure。我想在Clojure中编写我的游戏AI,然后在LibGDX for Android OS中完成其余的工作。
完成Clojure方面后,我使用 lein 命令将其打包到jar文件中(#lein compile,#lein run,#lein uberjar)。
我用右键单击项目>添加jar文件;属性> Java构建路径>图书馆>添加外部JAR ...> myai-0.1.0-快照standalone.jar
我执行游戏时出现问题。
import myai.*;
public class Stack extends Actor {
...
public void draw(SpriteBatch batch, float parentAlpha) {
System.out.println("Binomial = " + core.binomial(5, 15));
}
...
}
我收到此错误:
12-26 00:27:01.570: I/dalvikvm(8384): Could not find method myai.core.binomial, referenced from method my.package.Stack.draw
12-26 00:27:01.570: E/AndroidRuntime(2281): FATAL EXCEPTION: GLThread
12-26 00:27:01.570: E/AndroidRuntime(2281): java.lang.NoClassDefFoundError: myai.core
12-26 00:27:01.570: E/AndroidRuntime(2281): at my.package.Stack.draw(Stack.java:297)
12-26 00:27:01.570: E/AndroidRuntime(2281): at my.package.GameScreen.render(GameScreen.java:146)
12-26 00:27:01.570: E/AndroidRuntime(2281): at com.badlogic.gdx.Game.render(Game.java:46)
12-26 00:27:01.570: E/AndroidRuntime(2281): at my.package.MyGame.render(MyGame.java:23)
12-26 00:27:01.570: E/AndroidRuntime(2281): at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:487)
12-26 00:27:01.570: E/AndroidRuntime(2281): at com.badlogic.gdx.backends.android.surfaceview.GLSurfaceViewCupcake$GLThread.guardedRun(GLSurfaceViewCupcake.java:713)
12-26 00:27:01.570: E/AndroidRuntime(2281): at com.badlogic.gdx.backends.android.surfaceview.GLSurfaceViewCupcake$GLThread.run(GLSurfaceViewCupcake.java:646)
我真的不知道为什么会这样,因为我已经按照教程中的所有步骤进行了操作。
这些是我的clojure文件:
project.clj
(defproject myai "0.1.0-SNAPSHOT"
:description "AI for my game"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.5.1"]]
:aot [myai.core]
:main myai.core)
core.clj
(ns myai.core
(:gen-class
:name myai.core
:methods [#^{:static true} [binomial [int int] double]])
)
(defn binomial
"Calculate the binomial coefficient."
[n k]
(let [a (inc n)]
(loop [b 1
c 1]
(if (> b k)
c
(recur (inc b) (* (/ (- a b) b) c))))))
(defn -binomial
"A Java-callable wrapper around the 'binomial' function."
[n k]
(binomial n k))
(defn -main
[& args]
(println "My Game Artificial Intelligence")
(println (str "(binomial 5 3): " (binomial 5 3)))
)
提前致谢! :)
编辑:使用命令行命令在Ubuntu中无效。
答案 0 :(得分:1)
多么愚蠢的错误......我忘了查看属性中的Clojure .jar文件> Java构建路径> 订单和导出选项卡,因此在编译时未将其添加到类路径中。