0

I'm writing this code for an assignment and I would greatly appreciate anyone's help. It's supposed to be a "video game" (it's more like a choose your own adventure game), and I keep getting errors that say "NullPointerException."

On top of that I can't get my images to show up and my video in the code is not playing.

If anyone could possibly give me some pointers, I would sincerely appreciate your help because I honestly don't know what I'm doing wrong.

Thank you so much, here's my code.

    import processing.video.*;
    String PATH = "/Project_2_Scetch/data/video_library/img4.mp4";
    Movie mov;

    Capture cam;
    float xin, yin;
    int maxImages = 06;
    int imageIndex = 0;
    int value = 0;
    PImage img;
    PImage[] images = new PImage[maxImages]; 
    float positionX = xin;
    float positionY = yin;

    void setup() {
    size(1000, 650);
    smooth();
    noStroke();
    img = loadImage("img0.jpg");
    rectMode(CENTER);


    if (key == 's'){
      String[] cameras = Capture.list();

      if (cameras.length == 0) {
        println("There are no cameras available for capture.");
        exit();
       } else {
        println("Available cameras:");
        for (int i = 0; i < cameras.length; i++) {
          println(cameras[i]);
        }

    // The camera can be initialized directly using an 
    // element from the array returned by list():
    cam = new Capture(this, cameras[0]);
    cam.start();     
  }      

      for (int i = 0; i < images.length; i ++ ) {
        images[i] = loadImage( "img" + i + ".jpg" );}}

    }
     void movieEvent(Movie m) {
     m.read();
    }
    void draw() {
    background(50, 20, 120);
    {
     textSize(20);
     text("In this game, there is no such thing as sleep. You will be going about        my", 150, 70);
      text("endless day either procrastinating, or catching up on homework", 200,   110 );
     fill(255);
     text("To procrastinate for endless fun use Free Mode", 288, 150);
     fill(255);
    text("To catch up on my homework and experience existential terror, use Adventure Mode", 95, 190);
    fill(255);

  text("Free Mode (Press J)", 175, 338);
  fill(255);

  text("Adventure Mode (Press K)", 579, 340);
  fill(255);}


  if (key == 'j') {
    background(50, 20, 120);
    text("To take intentionally terrible selfies, press the (A) key.", 150, 300);
    fill(255);
    text("To rescue pets, press the (B) key.", 150, 350);
    fill(255);}

   if (key == 'a') {
    img = loadImage("img1.jpg");
    image(img, width/4, height/6);
    background(50, 20, 120);
    text("If you would like to continue taking terrible selfies, press the (G)  key.", 125, 320);
    text("If you would like to go back and do something else, press the (J) key.", 125, 350);
  }
  if (key == 'b'){
    img = loadImage("img6.jpg");
    background(50, 20, 120);
    text("If you would like to see more animals, press the (C) key.", 175, 320);
    text("If you would like to go back and do something else, press the (J)  key.", 175, 370);
  }

  if (key == 'c'){
 image(mov, 0, 0, width, height);
  }

  if (key == 'e'){
    img = loadImage("img5.jpg");
    background(50, 20, 120);  
    text("You seem like an animal lover. If you would like to watch Animal Planet, press the (D) key.", 50, 320);
    text("If you are not an animal lover, how dare you.", 50, 360);
    text("Press the spacebar to start over and rethink your life's choices.",      50, 390);
  }
 if (key == 'g'){
   img = loadImage("img7.jpg");
   background(50, 20, 120);  
   text("You seem to like taking selfies. If you would like to take some more funky fresh selfies,", 53, 300);
   text("then please hit the (H) key.", 53, 350);
  }
 if (key == 'h'){
   background(50, 20, 120); 
   img = loadImage("img4.jpg");
   text("Are you satisfied with this selfie? Would you like to take more selfies? If so, press the (M) key.", 40, 300);
   text("If not, then that's okay too. If you'd rather work on some homework, press the (K) key instead.", 40, 335);
  }

  if (key == 'm'){
   text("Hey. You like selfies. No judgement here. Press the (S) key and take your own selfies and keep them close.", 40, 300);
   text("If not, that's alright too. If you'd rather, press (K) to start on some homework :)", 40, 330);}

 if (key == 'd'){
    background(50, 20, 120);
    fill(50, 60, 170);
    text("Go on, click on the box, you animal!", 250, 160);
    fill(255);
    line(470, 0, 470, 530);
    line(0, 295, 355, 295);

  }
  //this is a hot too, but move onto the next thing.j
  if (key == 's'){
  if(cam.available() == true) {
    cam.read();
  }
     image(cam, 0, 0);
  // The following does the same, and is faster when just drawing the image
  // without any additional resizing, transformations, or tint.
  //set(0, 0, cam);
  }
 }


//work on this later, this as well is a hot mess. the rectangle NEEDS to show up
//and the mouseClicked NEEDS to work on ONLY the rectangle that will eventually show up
void mouseClicked() {
  if (mouseX < 470 && mouseY < 295){
    fill(255);
    rect(470, 295, 500, 340);
    link("http://www.animalplanet.com/tv-shows/"); 
  } else if (mouseX >470 && mouseY >295);{
   fill(50, 20, 120);
    }
  }
  • 1
    We can't compile your code without errors which prevents us from reproducing your problem. Post proper [SSCCE](http://sscce.org) / [MCVE](http://stackoverflow.com/help/mcve). – Pshemo Mar 18 '16 at 23:52
  • 1
    I see you have a ; you should remove at the last else if – Romy Mar 18 '16 at 23:52

0 Answers0