1

I'm using the Minim 2.2.0 library with JAVA. The library requires us to define a helper class defining two methods and pass an object of this class to the Minim constructor. I wrote the MinimHelper class as follows.

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;
    }
}

And I wrote my main as follows

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();
    }
}

However, I'm getting the following error in the console.

==== 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)

Please tell me where I'm doing wrong.

  • 1
    Where exactly is the `Butterfly.mp3` file located? – Kevin Workman Sep 09 '16 at 16:46
  • you have [multiple questions in a single question, only ask one question per question](https://www.google.com/#q=stackoverflow%20one%20question%20per%20question&rct=j), one is a duplicate the others are probably answered by @KevinWorkman with the visibility modifiers. –  Sep 09 '16 at 17:32
  • @JarrodRoberson Please note that this is a [tag:processing] question, and [Processing isn't Java](http://meta.stackoverflow.com/questions/321127/processing-java). This NPE isn't caused by the same thing as the canonical Java NPE question (or, at the very least, it's caused by a more complicated issue that deserve its own question). I'm voting to reopen the question. – Kevin Workman Sep 09 '16 at 17:38

1 Answers1

1

I think the sketchPath() and createInput() functions need to be public for Minim to be able to find them.

Going through the source, Minim eventually calls Class.getMethod() to get the functions you've defined. From the Java API (emphasis mine):

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

If that's not the problem: Make sure the Butterfly.mp3 file is where you're telling it to look.

Does C:\\Users\\Martin\\Downloads\\Butterfly.mp3 exist? Does it have the correct permissions?

For more information, you might try adding print statements inside your MinimHelper class. Are the functions being called? What are the values being passed to it?

Kevin Workman
  • 41,537
  • 9
  • 68
  • 107