I write the code to collect the data of Leap Motion, but show me a NullPointerException (at line 27).
I’m just a beginner in Processing, What can I do to solve this problem? Please help me.
This is coding:
import processing.serial.*;
import de.voidplus.leapmotion.*;
LeapMotion leap;
Serial myPort;
//PVector[] thumbMcp = new PVector[10];
void setup() {
size(600, 600);
background(255);
leap = new LeapMotion(this);
smooth(8);
noStroke();
println((Object[])Serial.list());
myPort = new Serial(this,"COM3", 57600);
}
void draw() {
background(255);
int fps = leap.getFrameRate();
fill(#00E310);
text(fps + "fps",20,20);
for (Hand hand : leap.getHands()) {
hand.draw();
pushMatrix();
//MCP
PVector thumbMcp = hand.getThumb().getRawPositionOfJointMcp();
PVector indexMcp = hand.getIndexFinger().getRawPositionOfJointMcp();
PVector middleMcp = hand.getMiddleFinger().getRawPositionOfJointMcp();
PVector ringMcp = hand.getRingFinger().getRawPositionOfJointMcp();
PVector pinkyMcp = hand.getPinkyFinger().getRawPositionOfJointMcp();
float[] tmcp = thumbMcp.array();
float[] imcp = indexMcp.array();
float[] mmcp = middleMcp.array();
float[] rmcp = ringMcp.array();
float[] pmcp = pinkyMcp.array();
//DIP
PVector thumbDip = hand.getThumb().getRawPositionOfJointDip();
PVector indexDip = hand.getIndexFinger().getRawPositionOfJointDip();
PVector middleDip = hand.getMiddleFinger().getRawPositionOfJointDip();
PVector ringDip = hand.getRingFinger().getRawPositionOfJointDip();
PVector pinkyDip = hand.getPinkyFinger().getRawPositionOfJointDip();
float[] tdip = thumbDip.array();
float[] idip = indexDip.array();
float[] mdip = middleDip.array();
float[] rdip = ringDip.array();
float[] pdip = pinkyDip.array();
//PIP
PVector thumbPip = hand.getThumb().getRawPositionOfJointPip();
PVector indexPip = hand.getIndexFinger().getRawPositionOfJointPip();
PVector middlePip = hand.getMiddleFinger().getRawPositionOfJointPip();
PVector ringPip = hand.getRingFinger().getRawPositionOfJointPip();
PVector pinkyPip = hand.getPinkyFinger().getRawPositionOfJointPip();
float[] tpip = thumbPip.array();
float[] ipip = indexPip.array();
float[] mpip = middlePip.array();
float[] rpip = ringPip.array();
float[] ppip = pinkyPip.array();
//==============================//
int [] tMcp = int(tmcp);
int [] iMcp = int(imcp);
int [] mMcp = int(mmcp);
int [] rMcp = int(rmcp);
int [] pMcp = int(pmcp);
int [] tDip = int(tdip);
int [] iDip = int(idip);
int [] mDip = int(mdip);
int [] rDip = int(rdip);
int [] pDip = int(pdip);
int [] tPip = int(tpip);
int [] iPip = int(ipip);
int [] mPip = int(mpip);
int [] rPip = int(rpip);
int [] pPip = int(ppip);
popMatrix();
//myPort.write(byte(mmcp));
/*println(mMcp[0]);
println(mMcp[1]);
println(mMcp[2]);*/
String Tmcp = "";
for (int i = 0; i<3; i++) {
if (i>0) {
Tmcp += ",";
}
Tmcp += tMcp[i];
}
String Imcp = "";
for (int i = 0; i<3; i++) {
if (i>0) {
Imcp += ",";
}
Imcp += iMcp[i];
}
String Mmcp = "";
for (int i = 0; i<3; i++) {
if (i>0) {
Mmcp += ",";
}
Mmcp += mMcp[i];
}
String Rmcp = "";
for (int i = 0; i<3; i++) {
if (i>0) {
Rmcp += ",";
}
Rmcp += rMcp[i];
}
String Pmcp = "";
for (int i = 0; i<3; i++) {
if (i>0) {
Pmcp += ",";
}
Pmcp += pMcp[i];
}
println(Tmcp,";",Imcp,";",Mmcp,";",Rmcp,";",Pmcp,"\n");
myPort.write(Tmcp);
myPort.write(Imcp);
myPort.write(Mmcp);
myPort.write(Rmcp);
myPort.write(Pmcp);
}
}