|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
nullpointerexception when calling AxisCamera getImage()
We are trying to follow the sample code for vision provided with java, in order to get our own started.
We are getting a nullpointerexception when this line of code is run ColorImage image = camera.getImage(); any advice on how to fix this / what is causing the exception? I can provide more detail if neccessary |
|
#2
|
||||
|
||||
|
Re: nullpointerexception when calling AxisCamera getImage()
Up near robotInit, make sure that the line initializing the camera isn't commented out.
|
|
#3
|
|||
|
|||
|
Re: nullpointerexception when calling AxisCamera getImage()
Its not, and I think that would generate a different exception anyway.
|
|
#4
|
|||
|
|||
|
Re: nullpointerexception when calling AxisCamera getImage()
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.
|
|
#5
|
||||
|
||||
|
Re: nullpointerexception when calling AxisCamera getImage()
Quote:
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);
}
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);
}
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);
}
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. |
|
#6
|
||||
|
||||
|
Re: nullpointerexception when calling AxisCamera getImage()
A follow-up to lineskier's recommendation: print the camera variable right after initializing it inside of robotInit().
Code:
public void robotInit() {
camera = AxisCamera.getInstance(); // get an instance of the camera
System.out.println( "Printing camera: " + camera );
cc = new CriteriaCollection(); // create the criteria for the particle filter
cc.addCriteria(MeasurementType.IMAQ_MT_AREA, AREA_MINIMUM, 65535, false);
}
Printing camera: null I am not sure what would make this return null...other than having a misconfigured Axis camera. If you open a web browser and type in a url of 10.xx.yy.11 (where the xxyy is 3673, your 4 digit team number), do you connect to the Axis camera? If not, then you will need to reconfigure your camera. Here is the WPI page for configuring an Axis camera: http://wpilib.screenstepslive.com/s/...an-axis-camera Good luck and post again if this doesn't help. Once you get it fixed, let us know what fixed it so that the thread becomes a resource for others. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|