While attempting to deploy our robot, We received the above error on a continuous loop. I’m very new to java and programming in general, and have tried my best to fix the problem but nothing I’ve tried has worked.
Any ideas would be great…
I can also provide further info upon request.
I highly recommend not uploading by hand. I think the file that might allow us to help you fix this error would be build.gradle, so if we could take a look at that, that’d be great. Also, if we could get the full error, that’d also be good.
Any simple git tutorial should help you get going.
Thank you, I will look into that and update the post with a new github file as soon as I can get that setup. I could also provide the build.gradle file right now if that would be helpful .
As for the error message, I will not have access to that information again till later tonight so I will update the post with that information asap.
I was able to figure this out by running ./gradlew simulateJava. It can be useful when your aren’t by your robot.
The problem with that line is that you are trying to add a requirement that is null. Robot.m_driveTrain is null at the time your MecanumDriver command is instantiated. If you look at your Robot.java, you have public static RobotContainer m_robotContainer = new RobotContainer(); before you have public static DriveTrain m_driveTrain = new DriveTrain();. That means that while new RobotContainer() is being executed, all the static variables below it are null.
A quick fix for this is to flip those two lines so that it’s like this:
public static DriveTrain m_driveTrain = new DriveTrain();
public static RobotContainer m_robotContainer = new RobotContainer();
A better solution would be to stop using static variables altogether and pass all your dependencies through the constructors. This would ensure that you don’t have any uninitialized static variables lying around.
How do i do this?
Is this simply a terminal command or is it more complicated?
will do!
I will update the post with the results and hopefully this will work
Where there any other instances of this or was this the only problem that popped up
Could you give me a quick rundown on how to do this or link to a tutorial or two?
I’m relatively new to this (first year coding a robot + i’m virtually solo)
What is the constructor and how do I pass these dependencies through them?
Also could you define dependencies cause I have a broad idea but I am not 100% sure.
Yup just a simple terminal command. I imagine that VS Code also has some shortcut to run it.
I have no idea. That’s one of the reasons I don’t like using static variables like that. It’s hard to tell that there’s going to be a problem until you run the program.
Here’s a thread that goes over it a bit: Dependency Injection vs. Static Access. You’ll notice that the TeleopDrive command requires you to give it a DriveBase when you do new TeleopDrive(some drive base here).
I googled “wpilib dependency injection” if you want to search for more examples.
public class Foo {
public Foo() {
// this is a constructor. The code in here runs when you do new Foo()
}
}
Dependencies is really just a general term for any object that is required somewhere in your code. Your MecanumDriver command has a dependency on a DriveTrain.
I know this is kind of a long shot But I was hoping you could help me identify the new error with my code. It is similar to the one in this thread
Error at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:342): Could not instantiate robot edu.wpi.first.wpilibj2.command.CommandScheduler!
I haven’t had the time to look into dependency injections because my team has been very rushed, which might be part of the problem here. I’m working with some really experimental stuff so there’s a few spots that might have gone wrong. These all involve the intake shooter subsystem, command, and sequence files.
The errors could related to my insantion of static variables, or my use of a parallel command group as the default.
Whatever the case, I’m very out of my element. I know this might not be possible for you which is understandable, I’ve made a separate post about this issue and am also working to find a solution myself. But any help you could provide would be incredibly appreciated.
at edu.wpi.first.wpilibj2.command.CommandScheduler.setDefaultCommand(CommandScheduler.java:364)
at edu.wpi.first.wpilibj2.command.Subsystem.setDefaultCommand(Subsystem.java:50)
at frc.robot.RobotContainer.configureButtonBindings(RobotContainer.java:33)
at frc.robot.RobotContainer.<init>(RobotContainer.java:43)
at frc.robot.Robot.<clinit>(Robot.java:39)
at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:322)
at edu.wpi.first.wpilibj.RobotBase.lambda$startRobot$0(RobotBase.java:443)
at java.base/java.lang.Thread.run(Thread.java:829)
Error at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:336): The robot program quit unexpectedly. This is usually due to a code error.
Error at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:342): Could not instantiate robot edu.wpi.first.wpilibj2.command.CommandScheduler!
That’s almost the full error. If cut off a few lines above it. Anyway, the problem is on this line: at frc.robot.RobotContainer.configureButtonBindings(RobotContainer.java:33). I cannot help further without the lines that were cut off.
Sorry, I was in a rush responding to your comment and didnt notice (Chief Delphi is very finnicki about spacing so it wasnt showing)
Here it is:
Error at frc.robot.RobotContainer.configureButtonBindings(RobotContainer.java:33): Unhandled exception instantiating robot edu.wpi.first.wpilibj2.command.CommandScheduler java.lang.IllegalArgumentException: Default commands should not end!
at edu.wpi.first.wpilibj2.command.CommandScheduler.setDefaultCommand(CommandScheduler.java:364)
at edu.wpi.first.wpilibj2.command.Subsystem.setDefaultCommand(Subsystem.java:50)
at frc.robot.RobotContainer.configureButtonBindings(RobotContainer.java:33)
at frc.robot.RobotContainer.<init>(RobotContainer.java:43)
at frc.robot.Robot.<clinit>(Robot.java:39)
at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:322)
at edu.wpi.first.wpilibj.RobotBase.lambda$startRobot$0(RobotBase.java:443)
at java.base/java.lang.Thread.run(Thread.java:829)
Error at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:336): The robot program quit unexpectedly. This is usually due to a code error.
The above stacktrace can help determine where the error occurred.
See https://wpilib.org/stacktrace for more information.
Error at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:342): Could not instantiate robot edu.wpi.first.wpilibj2.command.CommandScheduler!
@Oblarg any suggestions on how to set a ParallelCommandGroup as a default command on a subsystem? It looks like ParallelCommandGroups will return true in isFinished() when the command is not even running, which prevents it from being a default command.