Constants not being able to be resolved

Any help fixing this would be appreciated

Thank you

What exactly is the issue that you are having? What errors? Could you please post a screenshot?

Make sure your imports are correct.

1 Like

It is very difficult to help without seeing the code. Can you attach some code, or link to a GitHub repo? One idea off the top of my head is that you aren’t importing the right file, if your constants are stored separately.

1 Like

The photo didn’t upload with the post sorry

Are you importing the Constants file at the top of your file? is that file in your code? You can click Quick Fix and it might prompt you with the correct import.

I suspect you aren’t importing the Constants file correctly. Can you show your imports?

Edit: if your Constants.java file is in the root directory (same level as Robot.java) and you haven’t changed any project configuration stuff, the import should be import frc.robot.Constants.

It’s is meant to be like this correct

Yes, do you have a Constants.java file in your project alongside Robot.java?

no I do not have one in the project

You can’t import or reference a file that doesn’t exist. You should be able to create a file and class named Constants and put your constants in that file, and it’ll work fine.

1 Like

Then you need to make that file to store your constants. Many teams like to organize their constants per subsystems as subclasses. Here is an example: 2024-crescendo/src/main/java/frc/team3602/robot/Constants.java at main · frc3602/2024-crescendo · GitHub

If you would like to use constants for your ShooterSubsystem you would import them like this: import static frc.team3602.robot.Constants.ShooterConstants.*;.

2 Likes

One another organization strategy you could do, which is what we do, is have different Constants files for each subsystem, with each subsystem file and subsystem-constants file in their own folder (within the subsystems folder); you can look at our code here to see what that looks like. Then I don’t think you have to actually import them.

Additionally, I don’t know if you’re already aware of this, but MotorControllerGroup has been deprecated in the 2024 release of WPILib which is why it’s crossed out. Instead of using it, you could set one motor controller to follow the other. The version of the CANSparkMax constructor you’re using has also been deprecated – switch the motor type from CANSparkMaxLowLevel.MotorType to CANSparkLowLevel.MotorType and that should fix it.

1 Like