在 Java 中使用 Minim 库。无法让助手 class 工作

Using Minim library in Java. Couldn't get the helper class working

我在 JAVA 中使用 Minim 2.2.0 库。该库要求我们定义一个 helper class 来定义两个方法,并将此 class 的对象传递给 Minim 构造函数。我写了 MinimHelper class 如下。

public class MinimHelper {
    String sketchPath( String fileName ) {
        return "C:\Users\Martin\Downloads\"+fileName;
    }

    InputStream createInput(String fileName) {
        InputStream is = null;
        try{
            is = new FileInputStream(sketchPath(fileName));
        }
        catch(Exception e){
            System.out.println(e.toString());
        }
        return is;
    }
}

而我的主要写法如下

public class Main {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        AudioPlayer player;
        Minim minim = new Minim (new MinimHelper());
        player = minim.loadFile("Butterfly.mp3");
        player.play();
    }
}

但是,我在控制台中收到以下错误。

==== JavaSound Minim Error ====
==== Couldn't find a sketchPath method on the file loading object provided!
==== File recording will be disabled.

==== JavaSound Minim Error ====
==== Couldn't find a createInput method in the file loading object provided!
==== File loading will be disabled.

==== JavaSound Minim Error ====
==== Error invoking createInput on the file loader object: null

Exception in thread "main" java.lang.NullPointerException
    at ddf.minim.javasound.JSMinim.getAudioRecordingStream(Unknown Source)
    at ddf.minim.Minim.loadFile(Unknown Source)
    at ddf.minim.Minim.loadFile(Unknown Source)
    at Main.main(Main.java:9)

请告诉我哪里做错了。

我认为 sketchPath()createInput() 函数需要 public 才能让 Minim 找到它们。

正在经历 the source, Minim eventually calls Class.getMethod() to get the functions you've defined. From the Java API(强调我的):

Returns a Method object that reflects the specified public member method of the class or interface represented by this Class object.

如果这不是问题所在:确保 Butterfly.mp3 文件在您指定的位置。

C:\Users\Martin\Downloads\Butterfly.mp3存在吗?它是否具有正确的权限?

有关更多信息,您可以尝试在 MinimHelper class 中添加打印语句。函数被调用了吗?传递给它的值是什么?