Help, I don't know why I'm getting this error

I need some help.
When I deploy the code, I keep getting a error:

 `Unhandled exception: java.lang.IllegalStateException: A CANSparkMax instance has already been created with this device ID: 9
Error at com.revrobotics.CANSparkMaxLowLevel.<init>(CANSparkMaxLowLevel.java:137): Unhandled exception: java.lang.IllegalStateException: A CANSparkMax instance has already been created with this device ID: 9
at com.revrobotics.CANSparkMaxLowLevel.<init>(CANSparkMaxLowLevel.java:137)
The robot program quit unexpectedly. This is usually due to a code error.
The above stacktrace can help determine where the error occurred.
See https://wpilib.org/stacktrace for more information.
   from: edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:358)

at com.revrobotics.CANSparkMax.<init>(CANSparkMax.java:191)
The startCompetition() method (or methods called by it) should have handled the exception above.
at frc.robot.subsystems.Arm.<init>(Arm.java:42)
at frc.robot.Robot.robotInit(Robot.java:33)
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:436)
at frc.robot.Main.main(Main.java:23)
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 https://wpilib.org/stacktrace 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.
[phoenix-diagnostics] Server shutdown cleanly. (dur:0)
[phoenix] Library shutdown cleanly`

I’m confused because I only initialize one motor with this CAN ID in my code, and I checked my code and I made sure I only initialized one motor. I tried changing the motor ID to a different number but it still gave me the same error for some reason.

1 Like

3984-2023/testingPID2 at NEW-Pid-test · DesteoyerRZSS/3984-2023 (github.com)

Check REV Client if there are two devices on the same ID.

You’re creating two instances with the same ID. The second one is in Arm.Java. You’re either instantiating Arm twice or you have somewhere else in your code using the same id.

I checked and each id is only associated with one motor

Ok, I figured it out, it turns out I created of the arm class which probably initialize two of each motor in the class. THanks

Yeah, you have an Arm object in both Robot.java and RobotContainer.java. That would definitely do it.

1 Like

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