View Single Post
  #5   Spotlight this post!  
Unread 18-01-2014, 20:38
mwtidd's Avatar
mwtidd mwtidd is offline
Registered User
AKA: mike
FRC #0319 (Big Bad Bob)
Team Role: Mentor
 
Join Date: Feb 2005
Rookie Year: 2003
Location: Boston, MA
Posts: 714
mwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond repute
Re: nullpointerexception when calling AxisCamera getImage()

Quote:
Originally Posted by BigJ View Post
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.
__________________
"Never let your schooling interfere with your education" -Mark Twain
Reply With Quote