Does anyone know how to add additional classes/files to a project created from an FRC iterative template? I add a new .java file to my project that includes a new public class, methods, etc. I can see the new file in Netbeans file navigator, but when I try to declare the new class in my main .java file, it doesn’t find it as the system is only looking the WPI library. How can I get the project to recognize additional classes and methods from different files?
If you go to “New File” (Ctrl+N), it should add it in your project so it is seeable. Did you add it in a different package (different set of folders)? If so, hit Alt+Enter on the line where it gives you the error and it should say “Add import from …”
That’s the only problem I can see, if that’s not it, perhaps a bit more description?
Using alt-Enter I can add the file/class to the WPILib, but that is the only option. I’d prefer to add the files & classes to my project/src folder rather than modify the WPI library. Any thoughts?
We’ve found a bug in the Robot Drive WPI library class and we’re trying to hack a fix until an update is released from WPI. I’m bringing the class local to make the change, but I’m having issues referencing the local version of the class.
When adding the class locally the only option that comes up is the default package and I’m having issues with using some of the method declarations within the class.
I’m continuing to play the option and really appreciate your insight.
I would like to temporarily make the change to the library, but it’s read-only and I can’t seem to change the attribute. Any chances you know how to modify the WPI library attributes?
Still can’t seem to find a way to instantiate a class from a file other that the main. All attempts fail. Perhaps someone provide a brief outline to illustrate a simple example of creating a class in file “A” and using it in file “B”?
Quick, rudimentary example here. Two classes in same project and package. Main instantiates a new instance of the ManualDrive class, then invokes method driveMe() on it. This program will actually work btw
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.SimpleRobot;
public class Main extends SimpleRobot {
ManualDrive drive = new ManualDrive();
public void autonomous() {
}
public void operatorControl() {
while (this.isOperatorControl()) {
drive.driveMe();
}
}
}
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Joystick;
public class ManualDrive {
Jaguar jag1 = new Jaguar(1);
Jaguar jag2 = new Jaguar(2);
RobotDrive drive = new RobotDrive(jag1, jag2);
Joystick controllerOne = new Joystick(1);
// constructor, needed to instantiate, can be empty
public ManualDrive() {
}
public void driveMe() {
drive.arcadeDrive(controllerOne);
}
}