我正在进行一项任务,并且我在Processing中不断收到NullPointerException错误,这是什么以及我该怎么做才能修复它?

时间:2016-03-18 23:47:23

标签: java nullpointerexception processing

我正在编写此代码以进行任务,我将非常感谢任何人的帮助。它应该是一个"视频游戏" (它更像是一个选择你自己的冒险游戏),我不断收到错误,说'#34; NullPointerException。"

除此之外,我无法显示我的图片,而且代码中的视频无法播放。

如果有人能给我一些指示,我会真诚地感谢你的帮助,因为老实说,我不知道自己做错了什么。

非常感谢,这是我的代码。

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

0 个答案:

没有答案