Go to Post *POP!* I suppose I'll have to change my hair style to the John V-Neun now. - Billfred [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 18-01-2014, 18:14
Thundrio Thundrio is offline
Dedicated Racer
FRC #3673
 
Join Date: Feb 2011
Rookie Year: 2010
Location: The Internet
Posts: 67
Thundrio is on a distinguished road
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
__________________
Interested in a new way of playing old games?
visit http://www.speedrunslive.com for a way to make single player games multiplayer!
visit http://www.zeldaspeedruns.com to open up a new world for zelda lovers!
pm me here or at zsr for more information!
Reply With Quote
  #2   Spotlight this post!  
Unread 18-01-2014, 18:19
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 542
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Re: nullpointerexception when calling AxisCamera getImage()

Up near robotInit, make sure that the line initializing the camera isn't commented out.
Reply With Quote
  #3   Spotlight this post!  
Unread 18-01-2014, 18:21
Thundrio Thundrio is offline
Dedicated Racer
FRC #3673
 
Join Date: Feb 2011
Rookie Year: 2010
Location: The Internet
Posts: 67
Thundrio is on a distinguished road
Re: nullpointerexception when calling AxisCamera getImage()

Its not, and I think that would generate a different exception anyway.
__________________
Interested in a new way of playing old games?
visit http://www.speedrunslive.com for a way to make single player games multiplayer!
visit http://www.zeldaspeedruns.com to open up a new world for zelda lovers!
pm me here or at zsr for more information!
Reply With Quote
  #4   Spotlight this post!  
Unread 18-01-2014, 20:28
BigJ BigJ is offline
Registered User
AKA: Josh P.
FRC #1675 (Ultimate Protection Squad)
Team Role: Engineer
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Milwaukee, WI
Posts: 945
BigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond repute
Re: nullpointerexception when calling AxisCamera getImage()

Quote:
Originally Posted by Thundrio View Post
Its not, and I think that would generate a different exception anyway.
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.
Reply With Quote
  #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
  #6   Spotlight this post!  
Unread 19-01-2014, 01:49
mmaunu's Avatar
mmaunu mmaunu is offline
Registered User
FRC #2485 (W.A.R. Lords)
Team Role: Mentor
 
Join Date: Mar 2013
Rookie Year: 2010
Location: San Diego, CA
Posts: 89
mmaunu is a jewel in the roughmmaunu is a jewel in the roughmmaunu is a jewel in the roughmmaunu is a jewel in the rough
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);
    }
If camera is indeed null, as it almost certainly is, you will see this:
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.
__________________
2014 Las Vegas (Winners with 987, 2478; Excellence in Engineering)
2014 San Diego (Finalists with 987, 3250; Quality Award)
2013 Inland Empire (Winners with 1538, 968; Excellence in Engineering Award)
2013 San Diego (Finalists with 2984, 4322; Creativity Award)
2012 Las Vegas (Finalists with 2034, 3187; Quality Award)
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 22:34.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi