How do I call CANSparkMax motor controllers?

In Java, im trying to build my code which calls for Cansparkmax motor controllers, however i keep getting errors, and I’m really not sure how to call them. Can anyone help?

You have to use the new keyword: Java new Keyword

like this:

private CANSparkMax m_LeftFollower = new CANSparkMax(
            Constants.k_LeftDriveFollower1ID,
            MotorType.kBrushless
        );

To further add to this in Java things are objects. The CANSparkMax is a library for making CANSparkMax objects, but think of it like a blueprint for an object not a real object. It can be used to make new objects but it doesn’t actually exist in the world.

The new keyword is telling Java to allocate space for a new object that has all of the methods, variables, classes associated with CANSparkMax. You can’t however call the class directly without it being a new object. If it worked like that every motor on your bot would all have to have the same functions all the time and couldn’t each have their own settings, speed, etc.

The Rev spark max examples may also be of interest.