Java Dual Camera Code Help



I transferred/converted the example c++ code from the FIRST page for switching cameras into java. I have changed a few things to make it easier to read and I cannot get rid of this one error. “Cannot make a static reference to the non-static method getSubTable(String) from the type NetworkTable” I have been experimenting with the code and browsing the Internet for hours trying to find a solution. Our goal is to be able to switch between two cameras on the FRC Dashboard with one button. If anyone could help, or point me in the correct direction. I would really appreciate it.



I haven’t looked at the example code in a while, but you would need a NetworkTable instance most likely. You would get one by calling NetworkTable.getTable. there was likely a similar call in the c++ example.

One thing I did notice is you are still using eclipse with the old 2018 build setup. The eclipse setup does not work anymore, and when you try to install the 2019 image you’ll notice that will no longer work anymore. The new setup using vscode and Gradle. You can find steps to set up and install the new setup here.


Those NetworkTable lines aren’t important to what you’re trying to do, so you can simply remove them. Or alternatively, those lines should read:


and similarly for camera1.getName().

You should also remove the portion where you initialize the UsbCamera objects with new UsbCamera(null, 0);

Your functions are private so I don’t know how you’re going to call them, but if they were in the main robot class they should be robotInit() and teleopPeriodic().

One other tip: add to the initialization code the following for each camera:
This will keep both cameras open so switching between them is fast.

The article on screensteps is a bit out of date, we’ll work on updating it.


In regards to still using eclipse, I did this because after installing vscode I could not figure out how to add the Phoenix Framework from CTRE into it. I need this because we use SRX’s and hope to use some others in the future. How do I add such things into visual studio?


General documentation for how to install third party libraries into vscode is here:

CTRE also has documentation for their libraries, which includes installation instructions:


Are you trying to use the USBCamera class? That would make your life significantly easier. If not, that’s the limit of my expertise :grin: