我已经使用Matlab一段时间了,但刚刚开始使用Octave。我试图在我的Windows机器上使用以下代码读取midi文件:
javaaddpath('C:/Program Files/Java/jdk1.8.0_45/jre/lib/rt.jar');
midiFile = javaObject('java.io.File', file_name);
if ~midiFile.exists
error('Unable to find file %s',file_name);
end
seq = javaObject('javax.sound.midi.MidiSystem.getSequence', midiFile);
但是我收到以下错误:
error: [java] java.lang.ClassNotFoundException: javax.sound.midi.MidiSystem.getSequence
我做错了什么?
谢谢!
答案 0 :(得分:0)
函数javaObject()
用于调用类构造函数。但是,getSequence()
是javax.sound.midi.MidiSystem
类的“常规”方法。
octave> help javaObject
-- Built-in Function: JOBJ = javaObject (CLASSNAME)
-- Built-in Function: JOBJ = javaObject (CLASSNAME, ARG1, ...)
Create a Java object of class CLASSSNAME, by calling the class
constructor with the arguments ARG1, ...
octave> man javaMethod
-- Built-in Function: RET = javaMethod (METHODNAME, OBJ)
-- Built-in Function: RET = javaMethod (METHODNAME, OBJ, ARG1, ...)
Invoke the method METHODNAME on the Java object OBJ with the
arguments ARG1, ....
For static methods, OBJ can be a string representing the fully
qualified name of the corresponding class.
请注意,通常,javaMethod
的第二个参数是一个对象,但也可以是带有类名的字符串。因此,您需要这样做:
octave> midiFile = javaObject ("java.io.File", "Downloads/MIDI_sample.mid");
octave> seq = javaMethod ("getSequence", "javax.sound.midi.MidiSystem", midiFile )
seq =
<Java object: javax.sound.midi.Sequence>