Hi everyone I'm very new to processing but had to do my graduation project with it. Below is my code, but when closing minim I get "Null Pointer Exception" error. What can I do and what does it mean?
import processing.serial.*;
import processing.video.*;
import ddf.minim.*;
//BufferedReader input;
PrintWriter output;
AudioPlayer player;
Minim minim;
Capture myCapture;
Movie myMovie;
Serial myPort;  // Create object from Serial class
Boolean videoplaying = false;
Boolean captureon = false;
int val = 11;      // Data received from the serial port
int pir = 1;
int ldr = 1;
int pir_pre = 0;
int ldr_pre = 0;
int t = 0;
int timer = 0;
int imagenum = 1;
void setup() 
{
  size(320, 240, P2D);
  background(0);
  minim = new Minim(this);  
  //myMovie.loop();  
  myCapture = new Capture(this, width, height, 30);  
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);  
  // Create a new file in the sketch directory
  output = createWriter("bikbik.txt"); 
//  input = createReader("bikbik.txt");  
//  inputRead();
}
void draw()
{
  if ( myPort.available() > 0) {  // If data is available,
    val = myPort.read();         // read it and store it in val
  }  
  pir = val/10;
  ldr = val%10;  
  print("pir=");
  print(pir);
  print(" - ldr=");
  println(ldr);
  println(timer); 
if(pir == 0)
{
   timer=0;
}
if(ldr == 0){
  timer=1000;
}
if (timer >= 3000) {
  timer=1000;
}
if (timer<1000 && !videoplaying) {
  int rand = int(random(1,4));
  println(rand);
  player = minim.loadFile(""+rand+".mp3", 2048);
  myMovie = new Movie(this, ""+rand+".mov");
  player.cue(0);
  player.play();
  myMovie.play();
  videoplaying = true;
}
else if (timer >=1000 && videoplaying) {
  player.pause();
  myMovie.stop();
  videoplaying=false;
}
if (videoplaying) {
  image(myMovie, 0, 0, width, height);
}
timer++; 
 if(ldr == 0 && !captureon) {
   t = (millis())%10000;
   captureon = true;
   captureSave();
 }
 if (ldr == 1) {
   captureon = false;
 }
}
void movieEvent(Movie myMovie) {
  myMovie.read();
}
void captureSave()
{
  //rotateImage(myCapture, 180);
  image(rotateImage(myCapture, 180), 0, 0);
  //save(year()+"/"+month()+"/"+day()+"/"+minute()+"redhot.png");
  save("img"+imagenum+".jpg");
  imagenum++;
}
void captureEvent(Capture myCapture) {
  myCapture.read();
}
PImage rotateImage(PImage img, int angle)
{
  PImage rot;
  int numPixels = img.height*img.width;
  if (abs(angle) == 180) 
  { 
    rot = new PImage(img.width,img.height); 
  }
  else
  {
    rot = new PImage(img.height,img.width); 
  }
  img.loadPixels();  
  int rotpx = 0;
  for (int i = 0; i < numPixels; i++)
  {
      int x0 = i % img.width;
      int y0 = floor(i / img.width);      
      // for each pixel calculates new x & y coordinates and index
      if (angle == 90)
      {
        int x1 = abs(y0 + 1 - img.height);
        int y1 = x0;
        rotpx = x1 + (y1 * rot.width);
      }
      else if (angle == -90 || angle == 270)
      {
        int x1 = y0;
        int y1 = abs(x0 + 1 - img.width);
        rotpx = x1 + (y1 * rot.width);
      }
      else if (angle == 180 || angle == -180)
      {
        // 180 is the easiest, just flip the array index...
        rotpx = numPixels - 1 - i;
      }
      else
      {
        // angles other than 90/180 are far more complicated...
        println("Not implemented, sorry 

");
      }      
      rot.pixels[rotpx] = img.pixels[i];
  }
  rot.updatePixels();
  return rot;
}
void keyPressed() {
  output.println(imagenum);
  output.flush(); // Writes the remaining data to the file
  output.close(); // Finishes the file
  exit(); // Stops the program
}
/*
void inputRead ()
{
  String line1;
  //try {
    line1 = input.readLine();
  //} catch (IOException e) {
  //  e.printStackTrace();
  //  line1 = null;
  //}
  if (line1 == null) {
    // Stop reading because of an error or file is empty
    imagenum = 1;
  //  noLoop();  
  } else {
    String[] pieces = split(line1, TAB);
    int x = int(pieces[0]);
    imagenum = x + 1;
  }
}
*/
void stop()
{
 player.close();  minim.stop();
  super.stop();
}
Here is the error:
Exception in thread "Animation Thread" java.lang.NullPointerException
      at Bike_1_kb5.stop(Bike_1_kb5.java:230)
      at processing.core.PApplet.die(PApplet.java:2535)
      at processing.core.PApplet.die(PApplet.java:2545)
      at processing.video.Capture.init(Capture.java:241)
      at processing.video.Capture.<init>(Capture.java:154)
      at processing.video.Capture.<init>(Capture.java:115)
      at Bike_1_kb5.setup(Bike_1_kb5.java:58)
      at processing.core.PApplet.handleDraw(PApplet.java:1571)
      at processing.core.PApplet.run(PApplet.java:1496)
      at java.lang.Thread.run(Thread.java:613)