Quote:
Originally Posted by BigJ
In Java, a NullPointerException happens when you try to do something (like call a method or access a public variable) with a variable that is currently null. On that line of code, the only variable being accessed is camera.
|
Yeah, I ran into this exact exception with one of my student's earlier today. It was a good opportunity to explain why null pointers occur. As you stated the camera in camera.{something} is the only thing that could be null in this case.
This is the robot init directly from the sample code:
Code:
public void robotInit() {
//camera = AxisCamera.getInstance(); // get an instance of the camera
cc = new CriteriaCollection(); // create the criteria for the particle filter
cc.addCriteria(MeasurementType.IMAQ_MT_AREA, AREA_MINIMUM, 65535, false);
}
This is what it should look like after you uncomment the camera line
Code:
public void robotInit() {
camera = AxisCamera.getInstance(); // get an instance of the camera
cc = new CriteriaCollection(); // create the criteria for the particle filter
cc.addCriteria(MeasurementType.IMAQ_MT_AREA, AREA_MINIMUM, 65535, false);
}
After this the camera should not be null. If it is still null however I would add a log line, something like this:
Code:
public void robotInit() {
System.out.println("construct the camera");
camera = AxisCamera.getInstance(); // get an instance of the camera
cc = new CriteriaCollection(); // create the criteria for the particle filter
cc.addCriteria(MeasurementType.IMAQ_MT_AREA, AREA_MINIMUM, 65535, false);
}
Make sure that line executes.
Remember the vision sample is based off SimpleRobot. If you are using something like IterativeRobot, etc this function may not be automatically called by wpi lib.
Adding that log line will let you know whether or not that code is even being executed.