Skip to content

Commit 5a013c8

Browse files
authored
Fix null pointer exception in RB Tank drive article (#1739)
Can't get Robot Container joysticks during command static initialization or constructor since commands are instantiated before Robot Container constructor finishes. Move getting joysticks to command execution
1 parent 292d0eb commit 5a013c8

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

source/docs/software/wpilib-tools/robotbuilder/writing-code/robotbuilder-drive-tank.rst

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ Add the Code to do the Driving
334334
.. code-block:: java
335335
:linenos:
336336
:lineno-start: 11
337-
:emphasize-lines: 22-23, 51, 57
337+
:emphasize-lines: 48, 54
338338
339339
// ROBOTBUILDER TYPE: Command.
340340
@@ -357,9 +357,6 @@ Add the Code to do the Driving
357357
358358
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=VARIABLE_DECLARATIONS
359359
360-
private Joystick leftJoystick = RobotContainer.getInstance().getJoystick1();
361-
private Joystick rightJoystick = RobotContainer.getInstance().getJoystick2();
362-
363360
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTRUCTORS
364361
365362
@@ -386,7 +383,7 @@ Add the Code to do the Driving
386383
// Called every time the scheduler runs while the command is scheduled.
387384
@Override
388385
public void execute() {
389-
m_drivetrain.drive(leftJoystick.getY(), rightJoystick.getY());
386+
m_drivetrain.drive(RobotContainer.getInstance().getJoystick1().getY(), RobotContainer.getInstance().getJoystick2().getY());
390387
}
391388
392389
// Called once the command ends or is interrupted.

0 commit comments

Comments
 (0)