I am getting an error whenever I run auto. Can someone help me debug it? Here is a link to my code :
PID-Loop-Gyro-V1-latest-/Robot.java at master · 7657thunderbots/PID-Loop-Gyro-V1-latest- (github.com)
Here is the errors that show up in the terminal when running the code in a simulation.
auto selected: My Auto
Error at frc.robot.Auto2_balance.Run_Auto2_balance(Auto2_balance.java:30): Unhandled exception: java.lang.NullPointerException: Cannot invoke “frc.robot.DriveTrain.getAverageEncoderDistance()” because “this.drivetrain” is null
at frc.robot.Auto2_balance.Run_Auto2_balance(Auto2_balance.java:30)
at frc.robot.Robot.autonomousPeriodic(Robot.java:148)
at edu.wpi.first.wpilibj.IterativeRobotBase.loopFunc(IterativeRobotBase.java:344)
at edu.wpi.first.wpilibj.TimedRobot.startCompetition(TimedRobot.java:130)
at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:343)
at edu.wpi.first.wpilibj.RobotBase.lambda$startRobot$0(RobotBase.java:413)
at java.base/java.lang.Thread.run(Thread.java:833)
Warning at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:358): The robot program quit unexpectedly. This is usually due to a code error.
The above stacktrace can help determine where the error occurred.
See Reading Stacktraces — FIRST Robotics Competition documentation for more information.
Error at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:365): The startCompetition() method (or methods called by it) should have handled the exception above.
Warning at edu.wpi.first.wpilibj.IterativeRobotBase.printLoopOverrunMessage(IterativeRobotBase.java:387): Loop time of 0.02s overrun
Error at edu.wpi.first.wpilibj.MotorSafety.check(MotorSafety.java:139): DifferentialDrive… Output not updated often enough. See Using the WPILib Classes to Drive your Robot — FIRST Robotics Competition documentation for more information.
[phoenix-diagnostics] Server shutdown cleanly. (dur:0)
[phoenix] Library shutdown cleanly