在我當前的項目中,我有一個ArrayList的PVectors,它存儲3d點的xyz座標。我將ArrayList傳遞給另一個操作它的類,但是,這樣做時我得到一個NullPointerException。我假設其中一個PVectors爲空,但我通過爲(0,0,0)分配任何空對象來進行檢查,並且仍然收到錯誤。另外,有更多的PVectors或ArrayList的PVectors更有效率嗎?無論哪種方式,我仍然得到錯誤。這是產生它的線。嘗試將ArrayList傳遞給另一個類時獲取NullPointerException
trip.pass(pointCoordinates);
這裏是主類
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();
}
我可以粘貼多個類,如果它有助於澄清問題。謝謝!
我們展示錯誤 – skaffman 2011-01-14 04:10:22