I am java developer and pi4j begginer. I am developing java app that can control servo (raspberry pi 4 model b)
the error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/pi4j/wiringpi/Gpio
at me.Olex7iMatix.CatBotSoftware.Main.main(Main.java:9)
Caused by: java.lang.ClassNotFoundException: com.pi4j.wiringpi.Gpio
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 1 more
JRE system library: JavaSE-1.8
the code
package me.Olex7iMatix.CatBotSoftware;
import com.pi4j.wiringpi.Gpio;
public class Main {
public static void main(String[] args) {
Gpio.pwmWrite(2, 50);
}
}
Edit: I just read the erorr message properly, you may need to just install the package, Installation guide
You are missing quite a lot of lines to get a servo to work with an RPi/Java.
You firstly need to tell the Pi which GPIO pin you are using and the output mode of said pin
You also need to set the PWM Mode
And then set the PWM Range
Then you can set a loop do set the servo