Having problem with driving.

Whenever we try to drive in teleop period we get the error below. We have the compressor unconnected thats why you see the can error. However, we try changing the code for driving either for arcade or tank apparently none of them works. What’s the problem? is it in our code or there is something else?

code:
public void _arcadeDrive(double j, double r){
drive.arcadeDrive(j, r);
}

Log:
ERROR 1 Unhandled exception: java.lang.NullPointerException org.usfirst.frc.team6593.robot.subsystems.DriveTrain._arcadedrive(DriveTrain.java:52)
Warning at edu.wpi.first.wpilibj.Notifier.lambda$new$1(Notifier.java:108): Robots should not quit, but yours did!
ERROR 1 The loopFunc() method (or methods called by it) should have handled the exception above. edu.wpi.first.wpilibj.Notifier.lambda$new$1(Notifier.java:109)

You’re not initializing the “drive” variable

I did but not in this thread.

private final DifferentialDrive drive = RobotMap.drive;

Did you initialize RobotMap.drive before copying its value to drive? We can’t see any scope here: are they even different things? You may have been copying the null value back into the variable.

You have to call RobotMap.init() before anything else in robotInit():


public class Robot extends TimedRobot {

  @Override
  public void robotInit() {
    RobotMap.init();

    // ... other initialization code ...
  }

}

I did that and it’s the same problem. It’s something to do with the DifferentialDrive. Here’s the code from the RobotMap that I wrote, this is not the exact copy of our RobotMap:

import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import edu.wpi.first.wpilibj.Spark;
import edu.wpi.first.wpilibj.SpeedController;

public class RobotMap {

public static SpeedController driveTrainrightSC;
public static SpeedController driveTrainleftSC;
public static DifferentialDrive drive;

public static void init() {
RobotMap.init();

		driveTrainrightSC = new Spark(0);
		driveTrainleftSC = new Spark(1);

		drive = new DifferentialDrive(driveTrainleftSC, driveTrainrightSC );
		
		
		}

}

This is the error that keep on repeating itself when the enabled in teleop period.

ERROR 1 Unhandled exception: java.lang.NullPointerException org.usfirst.frc.team6593.robot.subsystems.DriveTrain._arcadeDrive(DriveTrain.java:46)
Warning at edu.wpi.first.wpilibj.Notifier.lambda$new$1(Notifier.java:108): Robots should not quit, but yours did!
ERROR 1 The loopFunc() method (or methods called by it) should have handled the exception above. edu.wpi.first.wpilibj.Notifier.lambda$new$1(Notifier.java:109)

RobotMap.init() has to be called in robotInit() in your main robot class, not in RobotMap

This will cause infinite recursion and throw a StackOverFlowError. This code will crash if you use it. You’re clearly not calling this method anywhere, otherwise your code would crash with a StackOverFlowError instead of a NullPointerException from attempting to use uninitialized variables.

Oh wow, thank you it happens to be working now smoothly. Sorry, I misunderstood you at first.