0

In my current project I have an ArrayList of PVectors that store xyz coordinates for 3d points. I'm passing the ArrayList to another class that manipulates it, however, I'm getting a NullPointerException when doing so. I'm assuming that one of the PVectors is null, but I checked for this by assigning any null objects to (0,0,0) and I'm still getting the error. Also, is it more effecient to have an array of PVectors or an ArrayList of PVectors? Either way I'm still getting the error. Here is the line that produces it.

 trip.pass(pointCoordinates); 

And here is the main class

import org.openkinect.*;
import org.openkinect.processing.*;

Kinect kinect;
 Trip trip;

boolean tripOn;

int w = 640;
int h = 480;
int distance = 5; 

float[] depthLookUp = new float[2048];
ArrayList pointCoordinates = new ArrayList();

float factor = 400;
float a = 0;
float angle = 0;
float frequency = .05;

void setup() {
  size(800,600,P3D);
  kinect = new Kinect(this);
  kinect.start();
  kinect.enableDepth(true);
  kinect.processDepthImage(false);
  stroke(255); 
  for (int i = 0; i < depthLookUp.length; i++) {
    depthLookUp[i] = rawDepthToMeters(i);
  }
  for(int i = 0; i < 31920; i++) {
   pointCoordinates.add(new PVector(0, 0, 0));
  }
}

void draw() {
  background(0);
  pushMatrix();
  translate(width/2 + width/3,height/2, -200);
  //add 1/3 width to account for rule of thirds 
  popMatrix();
  int[] depth = kinect.getRawDepth();
  calculate(depth);  
  if(!tripOn) {
   for(int i = 0; i < pointCoordinates.size(); i++) {
     PVector temp = (PVector) pointCoordinates.get(i);
     point(temp.x, temp.y, temp.z);
   }
  }
  if(frameCount % 10 == 0) {
    if(tripOn) {
     tripOn = false;
     trip.clear(); 
    }
    else {
     tripOn = true;
     trip.pass(pointCoordinates); 
   }
  }
  if(tripOn) trip.run();
}

void stop() {
  kinect.quit();
  super.stop();
}

I can paste more classes if it helps to clarify the problem. Thanks!

0

3 Answers 3

5

You are not initializing your "trip" variable and therefore a call to trip.pass(..) would throw the NullPointerException.

Sign up to request clarification or add additional context in comments.

2 Comments

You beat me to it by 19 seconds ;-)
Really? That usually happens to me all the time..this place seems so active sometimes..
4

You never seem to assign a value to the variable trip. That would certainly cause a NullPointerException at the line that you've shown.

Comments

1

From your code snippet its hard to get the source of your problem. But my first guess is a threading issue.

You are trying to use the trip.pass(pointCoordinates); in a worker thread. Although it appears that ArrayList pointCoordinates = new ArrayList(); is not part of that thread.

A possible solution could be: check whether the pointCoordinates is initialized or not. If not then wait for it to get initialized.

Update

My bad. I have missed out the initialization of the trip object. :(

My +1 to Dan Breslau and jerluc

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.