使用 javax.sound.midi.Sequencer 的 Clojure 问题
我正在尝试将一些 Java 类与 Clojure 一起使用。我已经用 Scala 成功尝试过,但用 Clojure 时,我得到了 IllegalArgumentException。
这是 API: http:// download.oracle.com/javase/1.4.2/docs/api/java/lang/reflect/Method.html
下面的代码:
(import '(javax.sound.midi MidiSystem Sequencer Sequence))
(def mySequencer (MidiSystem/getSequencer))
(def mySequence (Sequence. Sequence/PPQ 10))
((.setSequence mySequencer) mySequence)
抛出异常:
Exception in thread "main" java.lang.IllegalArgumentException: No matching field found: setSequence for class com.sun.media.sound.RealTimeSequencer (recordmidi.clj:0)
at clojure.lang.Compiler.eval(Compiler.java:5341)
at clojure.lang.Compiler.load(Compiler.java:5736)
at clojure.lang.Compiler.loadFile(Compiler.java:5699)
at clojure.main$load_script__6268.invoke(main.clj:213)
at clojure.main$script_opt__6296.invoke(main.clj:265)
at clojure.main$main__6314.doInvoke(main.clj:346)
at clojure.lang.RestFn.invoke(RestFn.java:409)
at clojure.lang.Var.invoke(Var.java:365)
at clojure.lang.AFn.applyToHelper(AFn.java:165)
at clojure.lang.Var.applyTo(Var.java:482)
at clojure.main.main(main.java:37)
Caused by: java.lang.IllegalArgumentException: No matching field found: setSequence for class com.sun.media.sound.RealTimeSequencer
at clojure.lang.Reflector.getInstanceField(Reflector.java:245)
at clojure.lang.Reflector.invokeNoArgInstanceMember(Reflector.java:267)
at user$eval__11.invoke(recordmidi.clj:4)
at clojure.lang.Compiler.eval(Compiler.java:5325)
... 10 more
在 Clojure 1.1.0 和 1.2.0 中尝试过。在 Scala 中运行良好。 我还尝试使用 Clojure 查看 Sequencer 类的方法,是的,setSequence(Sequence) 方法就在那里。
这是我遇到的 Java 调用的唯一问题。
I'm trying to use some Java-classes with Clojure. I've tried it with Scala with success, but with Clojure, I get an IllegalArgumentException.
Here's the API: http://download.oracle.com/javase/1.4.2/docs/api/java/lang/reflect/Method.html
The code below:
(import '(javax.sound.midi MidiSystem Sequencer Sequence))
(def mySequencer (MidiSystem/getSequencer))
(def mySequence (Sequence. Sequence/PPQ 10))
((.setSequence mySequencer) mySequence)
throws an exception:
Exception in thread "main" java.lang.IllegalArgumentException: No matching field found: setSequence for class com.sun.media.sound.RealTimeSequencer (recordmidi.clj:0)
at clojure.lang.Compiler.eval(Compiler.java:5341)
at clojure.lang.Compiler.load(Compiler.java:5736)
at clojure.lang.Compiler.loadFile(Compiler.java:5699)
at clojure.main$load_script__6268.invoke(main.clj:213)
at clojure.main$script_opt__6296.invoke(main.clj:265)
at clojure.main$main__6314.doInvoke(main.clj:346)
at clojure.lang.RestFn.invoke(RestFn.java:409)
at clojure.lang.Var.invoke(Var.java:365)
at clojure.lang.AFn.applyToHelper(AFn.java:165)
at clojure.lang.Var.applyTo(Var.java:482)
at clojure.main.main(main.java:37)
Caused by: java.lang.IllegalArgumentException: No matching field found: setSequence for class com.sun.media.sound.RealTimeSequencer
at clojure.lang.Reflector.getInstanceField(Reflector.java:245)
at clojure.lang.Reflector.invokeNoArgInstanceMember(Reflector.java:267)
at user$eval__11.invoke(recordmidi.clj:4)
at clojure.lang.Compiler.eval(Compiler.java:5325)
... 10 more
Tried in Clojure 1.1.0 and 1.2.0. Works fine in Scala.
I also tried looking at the methods of the Sequencer class using Clojure, and yes, the setSequence(Sequence) method is there.
This is the only problem with Java-calls I've had.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
在 REPL 中返回 nil,考虑到该方法的 void 返回值,这似乎是正确的(并且转换为 mySequencer.setSequence(mySequence) ,这听起来像您想要的)。
我也曾经在博客中介绍过使用 Clojure 中的 Java MIDI 库,也许它会有所帮助:
http://citizen428.net/档案/396
Try
This returns nil in the REPL, which seems about right given the method's void return value (and translates to mySequencer.setSequence(mySequence) which sounds like what you want).
I also once blogged about using Java MIDI libs from Clojure, maybe it helps a bit:
http://citizen428.net/archives/396