Go to Post Now if you'll excuse me, I need to develop the edible transistor. - sciguy125 [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 17-01-2017, 21:33
iterevo iterevo is offline
Registered User
FRC #0967
 
Join Date: Jan 2017
Location: Marion IA
Posts: 3
iterevo is an unknown quantity at this point
java.lang.NullPointerException

We have been trying to figure out the new CAN Talon libraries given to us this season. After looking through numerous examples, we cannot get around this error:

Code:
ERROR  1  ERROR Unhandled exception: java.lang.NullPointerException at [org.usfirst.frc.team967.robot.subsystems.DriveSubsystem.arcadeDrive(DriveSubsystem.java:27), org.usfirst.frc.team967.robot.commands.TeleOp_ArcadeDrive.execute(TeleOp_ArcadeDrive.java:23), edu.wpi.first.wpilibj.command.Command.run(Command.java:243), edu.wpi.first.wpilibj.command.Scheduler.run(Scheduler.java:206), org.usfirst.frc.team967.robot.Robot.teleopPeriodic(Robot.java:109), edu.wpi.first.wpilibj.IterativeRobot.startCompetition(IterativeRobot.java:130), edu.wpi.first.wpilibj.RobotBase.main(RobotBase.java:247)]  edu.wpi.first.wpilibj.RobotBase.main(RobotBase.java:249) 
 Error at edu.wpi.first.wpilibj.RobotBase.main(RobotBase.java:249): ERROR Unhandled exception: java.lang.NullPointerException at [org.usfirst.frc.team967.robot.subsystems.DriveSubsystem.arcadeDrive(DriveSubsystem.java:27), org.usfirst.frc.team967.robot.commands.TeleOp_ArcadeDrive.execute(TeleOp_ArcadeDrive.java:23), edu.wpi.first.wpilibj.command.Command.run(Command.java:243), edu.wpi.first.wpilibj.command.Scheduler.run(Scheduler.java:206), org.usfirst.frc.team967.robot.Robot.teleopPeriodic(Robot.java:109), edu.wpi.first.wpilibj.IterativeRobot.startCompetition(IterativeRobot.java:130), edu.wpi.first.wpilibj.RobotBase.main(RobotBase.java:247)] 
 WARNING: Robots don't quit! 
 ---> The startCompetition() method (or methods called by it) should have handled the exception above. 
 ➔ Launching «'/usr/local/frc/JRE/bin/java' '-Djava.library.path=/usr/local/frc/lib/' '-jar' '/home/lvuser/FRCUserProgram.jar'» 
 ********** Robot program starting ********** 
 NT: server: client CONNECTED: 10.9.67.144 port 56534 
 Default IterativeRobot.robotPeriodic() method... Overload me!
Here is the link to our github to view all our code: https://github.com/FRC-IronLions-967/2017SteamWorks

The robot code will build and deploy correctly, and shows no errors. However when you enable the robot, the robot code drops out after a couple seconds and the above error appears.

Thanks,
Any help is appreciated
Team 967
Reply With Quote
  #2   Spotlight this post!  
Unread 17-01-2017, 21:48
BenBernard BenBernard is offline
Registered User
FRC #5687 (The Outliers)
Team Role: Mentor
 
Join Date: Jan 2016
Rookie Year: 2015
Location: Portland, ME
Posts: 45
BenBernard is on a distinguished road
Re: java.lang.NullPointerException

Looks like you are instantiating your CANTalons in RobotMap.init, but I don't see any calls to that method. You probably want to call that from your Robot class on startup.

I'm don't think RobotMap is really the right place for the CANTalons, but that's a whole different issue unrelated to the error.
Reply With Quote
  #3   Spotlight this post!  
Unread 17-01-2017, 21:48
SamCarlberg's Avatar
SamCarlberg SamCarlberg is online now
GRIP, WPILib. 2084 alum
FRC #2084
Team Role: Mentor
 
Join Date: Nov 2015
Rookie Year: 2009
Location: MA
Posts: 136
SamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to behold
Re: java.lang.NullPointerException

Line 27, as of commit d16c532, cannot possibly throw a NullPointerException:

Code:
if((xAxis< deadBand) && (xAxis > -deadBand)){ xAxis=0;}
Are you sure the code on the robot is the same as the code on Github?


Edit: Ben's right. You declare the speed controllers in RobotMap, but never call init() so they're always going to be null.
__________________
WPILib
GRIP, RobotBuilder

Last edited by SamCarlberg : 17-01-2017 at 21:51.
Reply With Quote
  #4   Spotlight this post!  
Unread 17-01-2017, 22:02
iterevo iterevo is offline
Registered User
FRC #0967
 
Join Date: Jan 2017
Location: Marion IA
Posts: 3
iterevo is an unknown quantity at this point
Re: java.lang.NullPointerException

We are very sorry about the code not being up to date on the github, we were messing with the code to get rid of the error. We have updated that now.

As far as the CAN Talons being instantiated in Robot Map, we are calling them in the DriveSubsystem.java file

Thanks for the quick responses, hope that helps
Reply With Quote
  #5   Spotlight this post!  
Unread 17-01-2017, 22:14
SamCarlberg's Avatar
SamCarlberg SamCarlberg is online now
GRIP, WPILib. 2084 alum
FRC #2084
Team Role: Mentor
 
Join Date: Nov 2015
Rookie Year: 2009
Location: MA
Posts: 136
SamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to behold
Re: java.lang.NullPointerException

The issue is that when your subsystems are initialized, they get their values for all the RobotMap variables before those variables have been initialized. So you can either
  1. Initialize subsystems after calling RobotMap.init(); or
  2. Call RobotMap.init() in a static block in the RobotMap class; or
  3. Remove RobotMap.init() altogether and initialize its contents inline

What you're basically doing is:

Code:
Object a = null;
Object b = a; // set b to the _current_ value of a, which is null
a = new Object();

...

b.doSomething(); // null pointer exception!
__________________
WPILib
GRIP, RobotBuilder

Last edited by SamCarlberg : 17-01-2017 at 22:16.
Reply With Quote
  #6   Spotlight this post!  
Unread 19-01-2017, 20:18
iterevo iterevo is offline
Registered User
FRC #0967
 
Join Date: Jan 2017
Location: Marion IA
Posts: 3
iterevo is an unknown quantity at this point
Smile Re: java.lang.NullPointerException

Thank you very much. We were able to figure out our issue. We appreciate the help and the quick responses.

Team 967
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 13:15.

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