Start Competition error

ERROR 1 The startCompetition() method (or methods called by it) should have handled the exception above.

You’re going to need to post more of the output. The lines above that one will say what exception happened and where.

ERROR 1 Unhandled exception: java.lang.NullPointerException frc.robot.Robot.robotInit(Robot.java:45)
Warning at edu.wpi.first.wpilibj.RobotBase.startRobot(RobotBase.java:274): Robots should not quit, but yours did!
ERROR 1 The startCompetition() method (or methods called by it) should have handled the exception above. edu.wpi.first.wpilibj.RobotBase.startRobot(RobotBase.java:276)

Thats the complete error. I noticed it happened when I created a new project. I deployd it and there is no robot code. I deployed the old code and it works.

Can you post your Robot.java? Something on line 45 of that file is throwing a NullPointerException, but we’d need to see the file itself to diagnose why it’s crashing there.

/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018 FIRST. All Rights Reserved.                             */
/* Open Source Software - may be modified and shared by FRC teams. The code   */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project.                                                               */
/*----------------------------------------------------------------------------*/

package frc.robot;

import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.Joystick;


/**
 * The VM is configured to automatically run this class, and to call the
 * functions corresponding to each mode, as described in the TimedRobot
 * documentation. If you change the name of this class or the package after
 * creating this project, you must also update the build.gradle file in the
 * project.
 */
public class Robot extends TimedRobot {
  /**
   * This function is run when the robot is first started up and should be used
   * for any initialization code.
   */

  //***Controllers***
  private Joystick driver_Controller;

  //Compressor
  private Compressor airCompressor;

  //***Solenoids***
  private DoubleSolenoid transmission;

  @Override
  public void robotInit() {

//***Joystics Port Assigned***
 driver_Controller = new Joystick(0);

//***AirCompressor Start***
airCompressor.start();

//***Solenoid Id Assigned***
 transmission = new DoubleSolenoid(0, 1);

  }

  @Override
  public void autonomousInit() {
  }

  @Override
  public void autonomousPeriodic() {
  }

  @Override
  public void teleopInit() {
  }

  @Override
  public void teleopPeriodic() {

if(driver_Controller.getRawButtonPressed(1)){
  transmission.set(DoubleSolenoid.Value.kForward);
 }
 else if(driver_Controller.getRawButtonPressed(2)){
  transmission.set(DoubleSolenoid.Value.kReverse);
 }

  }

  @Override
  public void testInit() {
  }

  @Override
  public void testPeriodic() {
  }

}
1 Like

On line 45, you’re calling airCompressor.start(), but you haven’t assigned a value to your airCompressor variable yet, and so your code crashes. Just define it first with airCompressor = new Compressor(0); and you’re good to go.

1 Like

You need to initialize your airCompressor variable before you call airCompressor.start().
Oof I got sniped.

Is this new from this year?

Nope! That’s just how Java works, you’ll get a NullPointerException if you use a variable that is undefined or equal to null. I’m also pretty sure this method of controlling & creating Compressor objects has been around since the 2015 control system upgrade.

I’m also getting this error, ERROR 1 CTRE CAN Receive Timeout frc.robot.Main.main(Main.java:27)

Can you post your Main.java? This error normally pops up when you’re trying to use or access a CAN device that doesn’t exist (or can’t be seen by the robot).

1 Like

Yes, that was the problem. Thanks!

1 Like

Hey Dacosta How did you fix your “ERROR 1 CTRE CAN Receive Timeout” problem. Our programmer is having the same problem. Thanks.

I assigned the compressor an id, the default one is 0. For example:

Compressor airCompressor = new Compressor(0);