|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
(Java) Error calling subsystem method from command
I'm having trouble calling methods from subsystems on Netbeans. When I call DriveSystem, it shows up fine and the preset methods show up, but whenever I try to call a method that I created myself it gives me an error saying "cannot find symbol method doNothing()". I tried different subsystems and commands, and even tried renaming them, but nothing seems to work and I can't find anything that might cause an error.
Command Code: public class DriveDoNothing extends CommandBase { public DriveDoNothing() { requires(DriveSystem); } protected void execute() { DriveSystem.doNothing(); } } Subsystem Code: public class DriveSystem extends Subsystem { public void doNothing() { leftMotor.set(0.0); rightMotor.set(0.0); } } |
|
#2
|
||||
|
||||
|
Re: (Java) Error calling subsystem method from command
You're trying to call a non static method from a static context. You can either make the do nothing method static, along with the drive motors, or you can make an instance of the subsystem and call the method of that.
|
|
#3
|
|||||
|
|||||
|
Re: (Java) Error calling subsystem method from command
Quote:
Code:
public class CommandBase {
public static DriveSystem driveSystem = new DriveSystem();
...
}
Code:
public class DriveDoNothing extends CommandBase {
public DriveDoNothing() {
requires(driveSystem);
}
protected void execute() {
driveSystem.doNothing();
}
}
|
|
#4
|
|||
|
|||
|
Re: (Java) Error calling subsystem method from command
It worked! I'm so happy...this has been bugging me for so long, thank you very much.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|