Null Pointer Exceptions from WPILIB 2023

Hi! I’ve recently upgraded my to WPILIB 2023 (along with the firmware for our roboRio and the navX). However, I’m getting null pointer errors from my code, even though they didn’t show in the 2022 version. This is my code:

And here are my logs. Any help is appreciated. Thank you in advance!

  • Unhandled exception: java.lang.NullPointerException: Cannot read the array length because “” is null

  • Error at frc.robot.subsystems.Swerve.getSwerveModulePositions(Swerve.java:129): Unhandled exception: java.lang.NullPointerException: Cannot read the array length because “” is null

  • at frc.robot.subsystems.Swerve.getSwerveModulePositions(Swerve.java:129)

  • at frc.robot.subsystems.Swerve.(Swerve.java:44)

  • at frc.robot.subsystems.Limelight.(Limelight.java:24)

  • at frc.robot.RobotContainer.(RobotContainer.java:32)

  • at frc.robot.Robot.robotInit(Robot.java:37)

  • at edu.wpi.first.wpilibj.TimedRobot.startCompetition(TimedRobot.java:106)

  • at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:343)

  • at edu.wpi.first.wpilibj.RobotBase.startRobot(RobotBase.java:433)

  • at frc.robot.Main.main(Main.java:23)

from: edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:365)

On line 44 of Swerve.java you’re calling getSwerveModulePositions, which references mSwerveMods, which isn’t initialized until lines 45-50. Moving the code on line 44 after the code on lines 45-50 should fix that error.

2 Likes

Thank you so much! That got rid of all the errors. Thanks!

FYI, if you haven’t seen it yet - Reading Stacktraces — FIRST Robotics Competition documentation - check this out, it’ll give some info as to how Ryan figured out the lines of code to go look at.

2 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.