Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   java.lang.NullPointerException (http://www.chiefdelphi.com/forums/showthread.php?t=153843)

iterevo 17-01-2017 21:33

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

BenBernard 17-01-2017 21:48

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.

SamCarlberg 17-01-2017 21:48

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.

iterevo 17-01-2017 22:02

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

SamCarlberg 17-01-2017 22:14

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!


iterevo 19-01-2017 20:18

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


All times are GMT -5. The time now is 21:48.

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