Go to Post This isn't an engineering fair and demonstration, it's FRC. Defense is part of the game. You can't expect a good FRC team to just sit there and get clobbered by a full-court shooter; they're going to engineer a solution to the problem. - Kevin Sevcik [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 12-12-2014, 10:50 AM
Jaykus Jaykus is offline
Registered User
FRC #4145
 
Join Date: Dec 2014
Location: Worthington
Posts: 9
Jaykus is an unknown quantity at this point
(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);

}
}
Reply With Quote
  #2   Spotlight this post!  
Unread 12-12-2014, 10:54 AM
Bryce Paputa's Avatar
Bryce Paputa Bryce Paputa is offline
FF TSL: Frog Farce
FRC #0503 (Frog Force)
Team Role: Alumni
 
Join Date: Jan 2012
Rookie Year: 2008
Location: Novi Michigan
Posts: 454
Bryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond repute
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.
Reply With Quote
  #3   Spotlight this post!  
Unread 12-12-2014, 11:23 AM
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,712
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: (Java) Error calling subsystem method from command

Quote:
Originally Posted by Jaykus View Post
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:
Code:
public class DriveDoNothing extends CommandBase {

    public DriveDoNothing() {
        requires(DriveSystem);
    }


    protected void execute() {
        DriveSystem.doNothing();

    }
}
Subsystem Code:
Code:
public class DriveSystem extends Subsystem {

    public void doNothing() {

         leftMotor.set(0.0);

        rightMotor.set(0.0);

    }
}
What you need to do is declare a static instance of your subsystem in your CommandBase class.

Code:
public class CommandBase {

     public static DriveSystem driveSystem = new DriveSystem();
...
}
Then you use this static instance of the dirve system in your command.

Code:
public class DriveDoNothing extends CommandBase {

    public DriveDoNothing() {
        requires(driveSystem);
    }


    protected void execute() {
        driveSystem.doNothing();

    }
}
If you'd like more details of why this works the way it does I'd be happy to expand my explanation for you.
Reply With Quote
  #4   Spotlight this post!  
Unread 12-12-2014, 09:35 PM
Jaykus Jaykus is offline
Registered User
FRC #4145
 
Join Date: Dec 2014
Location: Worthington
Posts: 9
Jaykus is an unknown quantity at this point
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.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 08:56 AM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi