What is wrong with this?

edited May 2016 in Library Questions

I want to play some sounds when i click the mouse, but I get a NullPointerException error at the line with "second.close();" I know that this code can be done more easily, but I really need it like this, because I will add other things too. Can someone tell me what's wrong?

import ddf.minim.*;
Minim minim;
AudioPlayer first, second, third, fourth, fifth;
int n=0;

void setup(){
  minim = new Minim(this);
  first = minim.loadFile("first.mp3");
  second = minim.loadFile("second.mp3");
  third = minim.loadFile("third.mp3");
  fourth = minim.loadFile("fourth.mp3");
  fifth = minim.loadFile("fifth.mp3");

void draw(){

void mouseClicked(){
  } else {
  } else {
  } else {
  } else {
  } else {


  • Please edit your post to format the code

  • you don't declare third and so on...?

  • oh, sorry. i did that in the original code, but i forgot to do it here... so i dont think that that is the problem

  • Answer ✓

    Please post the actual code you're using.

    You're closing every sound except one each time you click the mouse. But once you close a sound for the first time, what should happen when you close it again? I wouldn't be surprised if it throws an exception.

    I'm not a minim expert, so I'm honestly not sure, but googling "Processing minim AudioPlayer NullPointerException" wouldn't be a bad place to start.

  • try second.pause(); instead?

  • KevinWorkman was right. all i had to do is re-load the sound files after closing them. my bad, sorry...

  • edited May 2015
    • If you intend on re-using the same object over & over, close() is the wrong thing to do!
    • As @Chrisir mentioned, a simple pause() is all you need.
    • loadFile() all the time is neither smart nor fast! [-X
    • Also use an array, or some other "container" class, to keep all your AudioPlayer instances! *-:)
  • oh, thank you! this made things A LOT easier! :)

  • Hello Guys.

    I got a little problem. I'm working with Processing 1.5.1 and I've downloaded the minim 2.2.2 library. When I want to run examples with the ddf.minim.ugens. import, the program tell me that the library is missing. But I've checked my libraries and the ugen folder is in my document with this architecture : document/Minim-2.2.2/src/ddf/minim/ugens

    I don't undestand. Sorry for my english anyway. Thanks.

  • edited May 2015
    • @bmodio, your question is completely unrelated to this thread!
    • It's about library installation rather than programming w/ it! :-\"
    • You shoulda opened your own thread then.
    • Both Processing 1 & 2 already comes bundled w/ Minim.
    • Only in Processing 3 we'd need to install it from "Import Library" -> "Add Library". :-B
Sign In or Register to comment.