How to make a condition of two fields? - java

Good afternoon, I need to add several conditions to validate two fields in the current code.
The Min field must not exceed the Max field. Min <Max / 5000
<4000 prohibited when entering.
The Max field must not be less than the Min field. Max <Min / 4000 <5000 prohibited when entering.
The Min field should not exceed the interval from the Max field, 500 units less can be entered.
For instance:
Min 4500 and Max 5000, 4400/5000, 4250/5000, 4501/5000 are prohibited to enter and above.
The Min and Max fields must not be equal. Min = Max is prohibited when entering.
code:
import controlP5.*;
ControlP5 cp5;
Textfield O;
Textfield OO;
void setup() {
size(700, 400);
PFont font = createFont("arial", 18);
cp5 = new ControlP5(this);
O = cp5.addTextfield("MIN")
.setPosition(20, 100)
.setSize(200, 40);
O.setInputFilter(ControlP5.INTEGER)
.setFont(font)
.setColor(color(255, 0, 0));
OO = cp5.addTextfield("MAX")
.setPosition(20, 170)
.setSize(200, 40);
OO.setInputFilter(ControlP5.INTEGER)
.setFont(font);
textFont(font);
}
void draw() {
if (keyPressed && OO.isFocus()) {
float n;
try {
n = Float.parseFloat(OO.getText().replace(',', '.'));
if (!(n >= 1 && n <= 12000)) {
throw new NumberFormatException(); // throw to catch below
}
}
catch (Exception e2) {
String t;
if (OO.getText().length() > 1) {
t = OO.getText().substring(0, OO.getText().length() - 1);
} else {
t = "";
}
OO.setText(t);
}
}
if (keyPressed && O.isFocus()) {
float n;
try {
n = Float.parseFloat(O.getText().replace(',', '.'));
if (!(n >= 1 && n <= 11500)) {
throw new NumberFormatException(); // throw to catch below
}
}
catch (Exception e2) {
String t;
if (O.getText().length() > 1) {
t = O.getText().substring(0, O.getText().length() - 1);
} else {
t = "";
}
O.setText(t);
}
}
background(0);
fill(255);
}

Overall it sounds like you're trying to have the user enter a range of valid values (where the minimum is always smaller than the maximum). There's already a ControlP5 controller for that: Range
Other than allowing to set a min and max value within a range is the constraint to keep a difference between max and min value of at least 500.
You could get away with making the Range slider handles 0px wide, essentially disabling them which means the range you set at the start (via setRangeValues) will be maintained:
import controlP5.*;
ControlP5 cp5;
Range range;
int rangeMinValue;
int rangeMaxValue;
void setup() {
size(700, 400);
PFont font = createFont("arial", 18);
cp5 = new ControlP5(this);
range = cp5.addRange("yourRange")
// disable broadcasting since setRange and setRangeValues will trigger an event
.setBroadcast(false)
.setFont(font)
.setPosition(50,50)
// notice the dimensions are proportional to the min/max range to avoid floating point values
.setSize(500,40)
// set minimum - maximum range here
.setRange(4000,5000)
// example: set initial (recommended) range values
.setRangeValues(4000, 4500)
// workaround to disable left/right handles contraining the range to 500
.setHandleSize(0)
// after the initialization we turn broadcast back on again
.setBroadcast(true)
;
textFont(font);
}
void draw() {
background(0);
fill(255);
}
void controlEvent(ControlEvent event) {
if(event.isFrom("yourRange")) {
// min and max values are stored in an array.
// access this array with controller().arrayValue().
// min is at index 0, max is at index 1.
rangeMinValue = int(event.getController().getArrayValue(0));
rangeMaxValue = int(event.getController().getArrayValue(1));
println("range:",rangeMinValue,"->",rangeMaxValue);
}
}
The one limitation is that ranges can't be > 500. If that's a requirment, you can still manually constrain the values (by setting the range min(low)/max(high) values):
import controlP5.*;
// range constants
final int RANGE_MIN = 4000;
final int RANGE_MAX = 5000;
// the smallest allowed difference between min/max values
final int RANGE_MIN_DIFFERENCE = 500;
final int RANGE_MID = RANGE_MIN + ((RANGE_MAX - RANGE_MIN) / 2);
ControlP5 cp5;
Range range;
int rangeMinValue;
int rangeMaxValue;
void setup() {
size(700, 400);
PFont font = createFont("arial", 18);
cp5 = new ControlP5(this);
range = cp5.addRange("yourCustomRange")
// disable broadcasting since setRange and setRangeValues will trigger an event
.setBroadcast(false)
.setFont(font)
.setPosition(50,50)
// notice the dimensions are proportional to the min/max range to avoid floating point values
.setSize(500,40)
// set minimum - maximum range here
.setRange(RANGE_MIN, RANGE_MAX)
// example: set initial (recommended) range values
.setRangeValues(RANGE_MIN, RANGE_MIN + RANGE_MIN_DIFFERENCE)
// after the initialization we turn broadcast back on again
.setBroadcast(true)
;
textFont(font);
}
void draw() {
background(0);
fill(255);
}
void controlEvent(ControlEvent event) {
if(event.isFrom("yourCustomRange")) {
// min and max values are stored in an array.
// access this array with controller().arrayValue().
// min is at index 0, max is at index 1.
int rangeMinInt = int(event.getController().getArrayValue(0));
int rangeMaxInt = int(event.getController().getArrayValue(1));
// if the values are within the desired range, update global values
if(rangeMaxInt - rangeMinInt >= RANGE_MIN_DIFFERENCE){
rangeMinValue = rangeMinInt;
rangeMaxValue = rangeMaxInt;
}else{
// otherwise check which side of the range should be constrained (right/max) or (left/min) to overwrite user input
if(rangeMaxInt > RANGE_MID){
range.setLowValue(rangeMaxInt - RANGE_MIN_DIFFERENCE);
}else{
range.setHighValue(rangeMinInt + RANGE_MIN_DIFFERENCE);
}
}
// values to use
println("range:",rangeMinValue,"->",rangeMaxValue);
}
}
If that takes too much space you can use Numberbox which compared to the text field has a few advantages:
you don't need to worry about string to integer conversion (it handles numbers by default)
you can set min/max values
Here's an example:
import controlP5.*;
ControlP5 cp5;
// range constants
final int RANGE_MIN = 4000;
final int RANGE_MAX = 5000;
// the smallest allowed difference between min/max values
final int RANGE_MIN_DIFFERENCE = 500;
final int RANGE_MID = RANGE_MIN + ((RANGE_MAX - RANGE_MIN) / 2);
int minValue;
int maxValue;
Numberbox inputMin;
Numberbox inputMax;
void setup() {
size(700, 400);
PFont font = createFont("arial", 18);
cp5 = new ControlP5(this);
inputMin = cp5.addNumberbox("minValue")
.setPosition(100,100)
.setSize(100,20)
.setFont(font)
.setScrollSensitivity(1.1)
// set initial acceptable range
.setMin(RANGE_MIN)
.setMax(RANGE_MAX)
// set default value
.setValue(4000)
;
inputMax = cp5.addNumberbox("maxValue")
.setPosition(100,150)
.setSize(100,20)
.setFont(font)
.setScrollSensitivity(1.1)
// set initial acceptable range
.setMin(RANGE_MIN)
.setMax(RANGE_MAX)
// set default value
.setValue(RANGE_MID + 1)
;
textFont(font);
}
void draw() {
constrainRangeInputs();
background(0);
fill(255);
text("minValue: " + minValue + "\n" +
"maxValue: " + maxValue, 10, 15);
}
void constrainRangeInputs(){
int rangeMinInt = (int)inputMin.getValue();
int rangeMaxInt = (int)inputMax.getValue();
//
if(abs(rangeMaxInt - rangeMinInt) < RANGE_MIN_DIFFERENCE){
if(rangeMaxInt > RANGE_MID){
inputMin.setValue(rangeMaxInt - RANGE_MIN_DIFFERENCE);
}else{
inputMax.setValue(rangeMinInt + RANGE_MIN_DIFFERENCE);
}
}
}
The logic constrain values to a minimum 500 difference is not 100% tight, there may some other edge cases I haven't considered. It's more of a way to illustrate ways of solving the problem so you're better equipt to do so.
I would recommend going through Processing > Examples > Contributed Libraries > ControlP5 and running the examples, in particular the controllers. You can prioritise the ones that sound closer to your current problem, but it's worth getting experience with the options so you can choose the best controllers/UI element to fit your problem.
The example may not include usage of every method the controller has, however there's a comment list at the bottom you could easily copy/paste/run immediately.
Additionally of course you have the full documentation

Related

Why does x return a 5 if its zero and returns another expression multiplied by 5 if not?

I have a snippet of code that will help in creating the graph of an entered polynomial however, I do not understand why x1 has to be initiated this way
I've tried to deconstruct the line but I have come up with nothing, the graph would just display the wrong ticks if x1 returns anything else but the original code.
here is the line where getting x (which is a private int within a class to create the GUI) being initiated:
mainPanel.x = (mainPanel.value.getText().isEmpty()) ? 0:
Integer.parseInt(mainPanel.value.getText());
here is the line where I am confused in:
int x1 = (mainPanel.x == 0) ? 5 : (int)
Math.sqrt(mainPanel.x * polynomial.getExponent()) * 5;
The getExponent method:
public int getExponent(){
// no negative polynomials
int t = -1;
for (Term term: listTerms){ //from ArrayList<Term> listTerms = new ArrayList<>();
if (t < term.getExponent())
t = term.getExponent();
}
return t;
}
the getExponent just returns this.exponent within the Term class
basically creating the whole graph would look like this:
GraphTest graph = new GraphTest(400, x1);
graph.setLayout(null);
graph.setPolynomial(polynomial);
graph.setVisible(true);
mainPanel.column2.add(graph);
graph.setBounds(21, 23, 400, 400);
on the GraphTest class, the default constructor:
public GraphTest(int size, double maxValue) {
this.size = size;
this.maxValue = maxValue;
setPreferredSize(new Dimension(size, size));
}

Making an object change direction when reaching a destination

I am very new to coding and my aim is to make and object (a lorry) change destination when it reaches the first one (site).
As for now, the lorry leaves its original place (concrete plant) and moves to the first site created. The user can add sites with mousePress (I used an array of sites). But then my lorry gets stuck on the first site and doesn't go to the next one. I also want the lorry to go to 2 sites and then come back to the concrete plant to then again leave for 2 sites etc...
Can somebody help me, I am desperate and my deadline is next Monday.
This is my code:
Lorry lorry;
int xCoord;
int yCoord;
ArrayList<Site> sites;
int siteSize = 30;
void setup() // What is called once at the beginning
{
size (500, 500);
xCoord = int(width/2);
yCoord = int(height/2);
//Creating empty Array List where store sites objects
sites = new ArrayList<Site>();
//Adding first site
sites.add(new Site(random(width), random(height), siteSize));
//storing lorries
lorry = new Lorry(xCoord, yCoord);
}
void draw() // Draw the background and concrete plant
{
background (235, 247, 255);
ellipse(xCoord, yCoord, 60, 60);
//Calling the sites
for (int i = sites.size () - 1; i>=0; i--) {
Site site = sites.get(i);
site.displaySites();
}
//calling the lorry functions
lorry.updateLorry();
}
void mousePressed() {
sites.add(new Site(mouseX, mouseY, siteSize));
}
class Site
{
float x,y;
float size;
Site (float xin, float yin, float sin)
{
x = xin;
y = yin;
size = sin;
}
void displaySites()
{
rectangle(x, y, 60, 60);
}
}
class Lorry
{
PVector location;
PVector concretePlant;
PVector velocity;
boolean changeDirection;
int siteNumber = 0;
Site destination;
Lorry(float xCoord, float yCoord)
{
concretePlant = new PVector(xCoord, yCoord); //Initial start point
location = new PVector(xCoord, yCoord); //Initial start point
velocity = new PVector(2, 2);
destination = sites.get(siteNumber);
changeDirection = false;
}
void displayLorry()
{
rectangle(location.x, location.y, 30, 30);
}
void Move()
{
float xdir = destination.x - location.x;
float ydir = destination.y - location.y;
PVector dir = new PVector (xdir, ydir);
dir.normalize();
location.add(dir);
}
void reachDestination()
{
if ((destination.x == location.x) && (destination.y == location.y)) {
siteNumber++; // siteNumber = siteNumber + 1;
destination = sites.get(siteNumber);
changeDirection = true;
}
}
void updateLorry()
{
displayLorry();
Move();
reachDestination();
}
}
You're super close Lily, literally.
If you print the values of destination and location you'll notice they're getting super close, however, due to the increments they never "meet". The values never match (aren't equal).
You could easily swap your equals conditions for a more practical threshold distance condition (e.g. if the distance between the destination and location are smaller than 1px):
void reachDestination()
{
println(destination,location);
//if ((destination.x == location.x) && (destination.y == location.y)) {
if(dist(destination.x,destination.y,location.x,location.y) < 1){
if(siteNumber < sites.size() -1){
siteNumber++; // siteNumber = siteNumber + 1;
destination = sites.get(siteNumber);
changeDirection = true;
}else{
println("reached final site");
}
println("reachDestination");
}
}
Bare in mind that dist() uses the square root which could become a slow calculation for a large number of sites (due to sqrt), however you could use the squared distance instead.
Additionally, PVector has a lerp() function that returns the interpolated position between two given positions (e.g. destination and site) and an interpolation amount (a value between 0.0 (start position) and 1.0 (end position)).
Here's a proof of concept sketch:
PVector[] destinations = {
new PVector(10,10),
new PVector(90,10),
new PVector(90,90),
new PVector(10,90)
};
float traversal = 0.0;
void setup(){
}
void draw(){
background(255);
//draw destinations
for(PVector d : destinations){
ellipse(d.x,d.y,9,9);
}
//calculate traversal
PVector traversed = traversePoints(destinations,0.01);
//draw traversal
ellipse(traversed.x,traversed.y,3,3);
}
PVector traversePoints(PVector[] destinations,float speed){
if(speed < 0){
speed = 0.05;
}
//increment full path traversal (the higher the increment, the faster the move)
traversal += speed;
//loop back to 0 when fully traversed
if(traversal > destinations.length) traversal = 0.0;
//compute the current point index
int pointIndex = (int)traversal;
//compute the local traversal (0.0 -> 1.0 = 0% to 100% in between two points: current and next)
float pointT = traversal - pointIndex;
//compute the next current point index
int pointIndexNext = (pointIndex + 1) % destinations.length;
//interpolate between current and next points using above local traversal, offsetting by the last mainHingeition)
return PVector.lerp(destinations[pointIndex],
destinations[pointIndexNext],
pointT);
}
You can actually run this as demo bellow:
var destinations;
var traversal = 0.0;
function setup(){
createCanvas(100,100);
destinations = [
createVector(10,10),
createVector(90,10),
createVector(90,90),
createVector(10,90)
];
}
function draw(){
background(255);
//draw destinations
for(var i = 0 ; i < destinations.length; i++){
var d = destinations[i];
ellipse(d.x,d.y,9,9);
}
//calculate traversal
var traversed = traversePoints(destinations,0.01);
//draw traversal
ellipse(traversed.x,traversed.y,3,3);
}
function traversePoints(destinations,speed){
if(speed < 0){
speed = 0.05;
}
//increment full path traversal (the higher the increment, the faster the move)
traversal += speed;
//loop back to 0 when fully traversed
if(traversal > destinations.length) traversal = 0.0;
//compute the current point index
var pointIndex = Math.floor(traversal);
//compute the local traversal (0.0 -> 1.0 = 0% to 100% in between two points: current and next)
var pointT = traversal - pointIndex;
//compute the next current point index
var pointIndexNext = (pointIndex + 1) % destinations.length;
//interpolate between current and next points using above local traversal, offsetting by the last mainHingeition)
return p5.Vector.lerp(destinations[pointIndex],
destinations[pointIndexNext],
pointT);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/p5.min.js"></script>

move across the same distance of a curve at increasing speeds

I have an object that I am trying to get to move in a smooth "arc". The x value of the object does not actually change, but the y value does.
The y value starts at -108, and needs to get to -37.5. Every iteration I want it to move the same distance in a shorter time. The issue is that it needs to decelerate and stop at -37.5 (this would be for half of the motion). When the current code runs the time stays the same, the distance increases. this does work for the first iteration.
This is what I have:
private void jump() {
int startV = 10;
float yVal;
float velocity;
int airTime = 1;
float currY = -108;
Main main = New Main();
// main.iter is the iteration
velocity = startV * (1 + (main.iter / 10));
while (airtime != 0) {
yVal = yVal + velocity;
velocity = velocity - (1 + (main.iter / 10));
if (currY < yVal) {
airtime++;
}
else {
airtime--;
}
}
yVal = -108;
}
EDIT:
main.iter is an int that increments by one

I can't get the calculations to work

I have a calculator that is suposed to figure the volume and the results come back as "0"
JButton btnCalculateVlmn = new JButton("Calculate Hot Tub Volume");
btnCalculateVlmn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
double width = 0, length = 0, depth = 0, volume = 0;
String lengthString, widthString, depthString;
lengthString = hotTubLengthText.getText();
widthString = hotTubWidthText.getText();
depthString = hotTubDepthText.getText();
try
{
if (rdbtnRoundTub.isSelected())
{
volume = Math.PI * Math.pow(length / 2.0, 2) * depth;
}
else
{
volume = Math.PI * Math.pow(length * width, 2)
* depth;
}
DecimalFormat formatter = new DecimalFormat("#,###,###.###");
hotTubVolumeText.setText("" + formatter.format(volume));
}
catch (NumberFormatException e)
{
labelTubStatus
.setText("Fill in all fields");
}
}
});
btnCalculateVlmn.setBounds(20, 200, 180, 20);
hotTubs.add(btnCalculateVlmn);
JButton Exit = new JButton("Exit");
Exit.setBounds(220, 200, 80, 20);
Exit.addActionListener(this);
hotTubs.add(Exit);
}
depth is declared as 0 and never overwritten... so the volume is always 0.
I guess you should do something like:
...
double width = 0, length = 0, depth = 0, volume = 0;
String lengthString, widthString, depthString;
lengthString = hotTubLengthText.getText();
widthString = hotTubWidthText.getText();
depthString = hotTubDepthText.getText();
depth = Double.valueOf(depthString);
length = Double.valueOf(lengthString);
width = Double.valueOf(widthString);
....
You forgot to convert the strings (lengthString, widthString and depthString) to doubles and assign them to your variables (length, width and depth).
you have depth = 0 and
anything * 0 = 0
you forgot to convert your strings from the input fields to double.
you get 0 as result because you set length and width to 0
In both branches of your main if condition your expressions ending * depth. However this depth variable seems to be set to 0 and not set to anything else. So volume will always be 0 since whatever you multiply by 0 will be 0.
Maybe you've wanted to use depthString. Something like this:
depth = Integer.parseInt(depthString);
if (rdbtnRoundTub.isSelected())
{
volume = Math.PI * Math.pow(length / 2.0, 2) * depth;
}
else
{
volume = Math.PI * Math.pow(length * width, 2) * depth;
}

Getting a NullPointerException at seemingly random intervals, not sure why

I'm running an example from a Kinect library for Processing (http://www.shiffman.net/2010/11/14/kinect-and-processing/) and sometimes get a NullPointerException pointing to this line:
int rawDepth = depth[offset];
The depth array is created in this line:
int[] depth = kinect.getRawDepth();
I'm not exactly sure what a NullPointerException is, and much googling hasn't really helped. It seems odd to me that the code compiles 70% of the time and returns the error unpredictably. Could the hardware itself be affecting it?
Here's the whole example if it helps:
// Daniel Shiffman
// Kinect Point Cloud example
// http://www.shiffman.net
// https://github.com/shiffman/libfreenect/tree/master/wrappers/java/processing
import org.openkinect.*;
import org.openkinect.processing.*;
// Kinect Library object
Kinect kinect;
float a = 0;
// Size of kinect image
int w = 640;
int h = 480;
// We'll use a lookup table so that we don't have to repeat the math over and over
float[] depthLookUp = new float[2048];
void setup() {
size(800,600,P3D);
kinect = new Kinect(this);
kinect.start();
kinect.enableDepth(true);
// We don't need the grayscale image in this example
// so this makes it more efficient
kinect.processDepthImage(false);
// Lookup table for all possible depth values (0 - 2047)
for (int i = 0; i < depthLookUp.length; i++) {
depthLookUp[i] = rawDepthToMeters(i);
}
}
void draw() {
background(0);
fill(255);
textMode(SCREEN);
text("Kinect FR: " + (int)kinect.getDepthFPS() + "\nProcessing FR: " + (int)frameRate,10,16);
// Get the raw depth as array of integers
int[] depth = kinect.getRawDepth();
// We're just going to calculate and draw every 4th pixel (equivalent of 160x120)
int skip = 4;
// Translate and rotate
translate(width/2,height/2,-50);
rotateY(a);
for(int x=0; x<w; x+=skip) {
for(int y=0; y<h; y+=skip) {
int offset = x+y*w;
// Convert kinect data to world xyz coordinate
int rawDepth = depth[offset];
PVector v = depthToWorld(x,y,rawDepth);
stroke(255);
pushMatrix();
// Scale up by 200
float factor = 200;
translate(v.x*factor,v.y*factor,factor-v.z*factor);
// Draw a point
point(0,0);
popMatrix();
}
}
// Rotate
a += 0.015f;
}
// These functions come from: http://graphics.stanford.edu/~mdfisher/Kinect.html
float rawDepthToMeters(int depthValue) {
if (depthValue < 2047) {
return (float)(1.0 / ((double)(depthValue) * -0.0030711016 + 3.3309495161));
}
return 0.0f;
}
PVector depthToWorld(int x, int y, int depthValue) {
final double fx_d = 1.0 / 5.9421434211923247e+02;
final double fy_d = 1.0 / 5.9104053696870778e+02;
final double cx_d = 3.3930780975300314e+02;
final double cy_d = 2.4273913761751615e+02;
PVector result = new PVector();
double depth = depthLookUp[depthValue];//rawDepthToMeters(depthValue);
result.x = (float)((x - cx_d) * depth * fx_d);
result.y = (float)((y - cy_d) * depth * fy_d);
result.z = (float)(depth);
return result;
}
void stop() {
kinect.quit();
super.stop();
}
And here are the errors:
processing.app.debug.RunnerException: NullPointerException
at processing.app.Sketch.placeException(Sketch.java:1543)
at processing.app.debug.Runner.findException(Runner.java:583)
at processing.app.debug.Runner.reportException(Runner.java:558)
at processing.app.debug.Runner.exception(Runner.java:498)
at processing.app.debug.EventThread.exceptionEvent(EventThread.java:367)
at processing.app.debug.EventThread.handleEvent(EventThread.java:255)
at processing.app.debug.EventThread.run(EventThread.java:89)
Exception in thread "Animation Thread" java.lang.NullPointerException
at org.openkinect.processing.Kinect.enableDepth(Kinect.java:70)
at PointCloud.setup(PointCloud.java:48)
at processing.core.PApplet.handleDraw(PApplet.java:1583)
at processing.core.PApplet.run(PApplet.java:1503)
at java.lang.Thread.run(Thread.java:637)
You are getting a NullPointerException since the value of the depth array is null. You can see from the source code of the Kinect class, there is a chance of a null value being returned by the getRawDepth() method. It is likely that there is no image being displayed at the time.
The code can be found at:
https://github.com/shiffman/libfreenect/blob/master/wrappers/java/processing/KinectProcessing/src/org/openkinect/processing/Kinect.java
Your code should check if the depth array is null before trying to process it. For example...
int[] depth = kinect.getRawDepth();
if (depth == null) {
// do something here where you handle there being no image
} else {
// We're just going to calculate and draw every 4th pixel (equivalent of 160x120)
int skip = 4;
// Translate and rotate
translate(width/2,height/2,-50);
rotateY(a);
for(int x=0; x<w; x+=skip) {
for(int y=0; y<h; y+=skip) {
int offset = x+y*w;
// Convert kinect data to world xyz coordinate
int rawDepth = depth[offset];
PVector v = depthToWorld(x,y,rawDepth);
stroke(255);
pushMatrix();
// Scale up by 200
float factor = 200;
translate(v.x*factor,v.y*factor,factor-v.z*factor);
// Draw a point
point(0,0);
popMatrix();
}
}
// Rotate
a += 0.015f;
}
I would suggest using a Java Debugger so that you can see the state of the variables at the time the exception is thrown. Some people also like to use log statements to output the values of the variables at different points in the application.
You can then trace the problem back to a point where one of the values is not populated with a non-null value.
The null pointer is happening when offset > kinect.getRawDepth();
You have a lot of code here, I'm not going to look at it all. Why can you assume that offset is < kinect.getRawDepth()?
Edit:
On second though, #Asaph's comment is probably right.
Null Pointer exception happens when depth[offset] does not exist or has not been allocated. Check when depth[offset] is undefined and that is the cause of the nullpointer exception.
Check when kinect.getRawDepth(); is greater than offset.

Categories

Resources