我已經建立了包含在pi4j庫中的項目jar文件。當我試圖發動對樹莓的jar文件LCD 1602和PI4J樹莓
sudo java -jar LCD1602.jar
我有這樣的錯誤:
Exception in thread "main" java.lang.NoClassDefFoundError: com/pi4j/io/gpio/GpioFactory
at lcd1602.LCD1602.main(LCD1602.java:19)
Caused by: java.lang.ClassNotFoundException: com.pi4j.io.gpio.GpioFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
源碼:
package lcd1602;
import com.pi4j.component.lcd.LCDTextAlignment;
import com.pi4j.component.lcd.impl.GpioLcdDisplay;
import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.RaspiPin;
import com.pi4j.system.NetworkInfo;
public class LCD1602 {
public final static int LCD_ROW_1 = 0;
public final static int LCD_ROW_2 = 1;
public static void main(String[] args) throws Exception {
System.out.println("16X2 LCD Example with Raspberry Pi using Pi4J and JAVA");
// create gpio controller
final GpioController gpio = GpioFactory.getInstance();
// initialize LCD
final GpioLcdDisplay lcd = new GpioLcdDisplay(2, // number of row supported by LCD
16, // number of columns supported by LCD
RaspiPin.GPIO_23, // LCD RS pin
RaspiPin.GPIO_24, // LCD strobe pin
RaspiPin.GPIO_04, // LCD data bit D4
RaspiPin.GPIO_17, // LCD data bit D5
RaspiPin.GPIO_27, // LCD data bit D6
RaspiPin.GPIO_22); // LCD data bit D7
lcd.clear();
Thread.sleep(1000);
lcd.write(LCD_ROW_1, "WeArGenius");
lcd.write(LCD_ROW_2, " ???");
Thread.sleep(2000);
for (String ipAddress : NetworkInfo.getIPAddresses()){
System.out.println("IP Addresses : " + ipAddress);
lcd.writeln(LCD_ROW_2,ipAddress,LCDTextAlignment.ALIGN_CENTER);
}
gpio.shutdown();
}
}
我已手動導入pi4j的JAR的文件中的項目。感謝您的幫助
需要包含在類路徑中pi4j罐子。編譯時類路徑並不意味着運行運行時會自動相同。它們不是像C – slipperyseal
那樣靜態編譯還要確保你在pi上安裝了pi4j,因爲它安裝了pi4j罐子需要的本地庫 – slipperyseal