How we did it was we made a compressor object.
Compressor myCompressor = new Compressor(1,1); //the first number being the digitalIO port for the compressor, and the second being the relay port the spike is plugged into
And then in operatorControl() and where ever else before you start looping do myCompressor.start();
If that doesn't make sense please tell me and I'll clarify.
Also we had a problem where our code was correct but the ribbon cable from the c-rio to the sidecar was not working, and when we replaced that it worked.
EDIT: example
Code:
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.Relay;
import edu.wpi.first.wpilibj.SimpleRobot;
public class RobotTemplate extends SimpleRobot
{
private int spikePort = 1;
private int compressorPort = 1;
private Compressor airCompressor;
public void robotInit()
{
airCompressor = new Compressor(compressorPort, spikePort);
}
public void autonomous()
{
System.err.println("Entering autonomous:");
airCompressor.start();
while(isEnabled())
{
}
}
public void operatorControl()
{
System.err.println("Entering teleop:");
airCompressor.start();
while(isEnabled())
{
}
}
public void test()
{
System.err.println("Entering Test:");
}
}