# Getting a NullPointerException with opencv loadImage()!

**URL:** <https://discourse.processing.org/t/getting-a-nullpointerexception-with-opencv-loadimage/31739>\
**Category:** Libraries\
**Created:** [August 16, 2021, 7:57am UTC](https://discourse.processing.org/t/getting-a-nullpointerexception-with-opencv-loadimage/31739 "2021-08-16T07:57:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![maroslan](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@maroslan](https://discourse.processing.org/u/maroslan)\
**Post date:** [August 16, 2021, 7:57am UTC](https://discourse.processing.org/t/getting-a-nullpointerexception-with-opencv-loadimage/31739/1 "2021-08-16T07:57:58Z")

</div>

I need someone more skilled than me to look at my code. I am trying to open my webcam, and make it track a location, where it will draw a circle. However, it wont even load the cam! I get a NullPointerException. I see there must be an easy solution, but I cannot find it.

```auto
import processing.video.*;
import gab.opencv.*;

Capture cam;
OpenCV opencv;
PVector prevLoc;

void setup() {
  size(1920, 1080);
  //background(255);
  noStroke();
  
  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]);
    }
    cam = new Capture(this, 1920, 1080, cameras[1]);
    cam.start(); 
    prevLoc = new PVector(0, width/2);
    frameRate(24);
  }
}

void captureEvent(Capture cam) {
  if (cam.available() == true) {
    cam.read();
  }
  image(cam, 0, 0);
}

void draw() {
  opencv.loadImage(cam); //Here I get the NullPointerException error
  PVector loc = opencv.min();
  ellipse(loc.x, loc.y, 50, 50);
  prevLoc = loc;
}

void keyPressed() {
  if (key == ' ') {
    background(255);
  }
}

```

---

<div class="post-metadata">

**Author:** ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)\
**Post date:** [August 17, 2021, 5:24pm UTC](https://discourse.processing.org/t/getting-a-nullpointerexception-with-opencv-loadimage/31739/2 "2021-08-17T17:24:25Z")

</div>

same issue with the other thread - please post link to other forums [https://www.reddit.com/r/processing/comments/p5bydt/nullpointerexception\_error\_with\_loadimage\_using\_a/](https://www.reddit.com/r/processing/comments/p5bydt/nullpointerexception_error_with_loadimage_using_a/)  
(and it’s answered on reddit already)
