|
Working with java classes
Hello,
I'm a programmer on an FRC team trying to work with Java. In previous years, we've programmed in C++, and we're making the switch this year. My question is on calling methods in the main class from other classes. Specifically, I'm trying to setup a separate thread for vacuum control, and would like to check whether the robot is enabled. Unfortunately, I cannot check RobotCode.isEnabled(), with the error "non-static method isEnabled() cannot be referenced from a static context". The same error pops up when attempting to access the Jaguar controlling the vacuum or the joystick's trigger. I understand why the error occurs, as these attempts access the class as opposed to its instance, however I do not know how I would work around this. Declaring the joystick and jaguar as static allow access to those, but I still cannot check isEnabled(). How would I check it? I could have a loop in RobotCode updating a static variable, but is there a better solution?
EDIT: I found that placing the vacuum class within the main class fixed the issue. It worked, but if anyone has a cleaner solution I would very much like to hear it.
Last edited by correnos : 13-01-2011 at 11:38.
|