Help: Null Pointer Exception

Our team is relatively new to command based programming. We’re trying to run a simple tank drive command for our DriveTrain subsystem. We keep getting a Null Pointer Exception when we try to execute our Tank Drive Command.

Our code is hosted on gitHub.

Here is the Riolog output:

Default robotPeriodic() method... Overload me!
Exception in thread "Thread-0" java.lang.NullPointerException
	at org.usfirst.frc.team3245.robot.commands.TankDrive.execute(TankDrive.java:24)
	at edu.wpi.first.wpilibj.command.Command.run(Command.java:238)
	at edu.wpi.first.wpilibj.command.Scheduler.run(Scheduler.java:220)
	at org.usfirst.frc.team3245.robot.Robot.teleopPeriodic(Robot.java:129)
	at edu.wpi.first.wpilibj.IterativeRobotBase.loopFunc(IterativeRobotBase.java:213)
	at edu.wpi.first.wpilibj.TimedRobot.lambda$new$0(TimedRobot.java:30)
	at edu.wpi.first.wpilibj.Notifier.lambda$new$0(Notifier.java:97)
	at java.lang.Thread.run(Thread.java:748)
ERROR  1  DifferentialDrive... Output not updated often enough.  edu.wpi.first.wpilibj.MotorSafetyHelper.check(MotorSafetyHelper.java:108)

Error at edu.wpi.first.wpilibj.MotorSafetyHelper.check(MotorSafetyHelper.java:108): DifferentialDrive... Output not updated often enough.
ERROR  1  DifferentialDrive... Out
Exception in thread "Thread-0" java.lang.NullPointerException
	at org.usfirst.frc.team3245.robot.commands.TankDrive.execute(TankDrive.java:24)
	at edu.wpi.first.wpilibj.command.Command.run(Command.java:238)

Looking at line 24 of TankDrive.java, there are two variables mentioned. I can see where Robot.DriveTrain is initialized but not Robot.OI.

Looks like this line is where the exception is happening. The two possibilities are Robot.drivetrain is null or Robot.oi is null.

I see Robot.drivetrain is initialized in robotInit(), however, it looks like Robot.oi is not.

To fix this, add the following line here:

oi = new OI();