i have builded the jar file of project with the inclusion in library of pi4j. When i try to launch the jar file on the raspberry
sudo java -jar LCD1602.jar
i have this error:
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
SourceCode:
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();
}
}
i have imported manually the jar's file of pi4j inside the project. Thanks for help
解决,将lib文件夹(包含pi4j的所有jar)添加到jar目录中。
package i2clcddisplaytest; import com.pi4j.component.lcd.impl.I2CLcdDisplay; import com.pi4j.component.lcd.*; public class I2cLcdDisplayTest { public static void main(String[] args) throws Exception { I2CLcdDisplay lcd = new I2CLcdDisplay( 2, // * @param rows 16, // * @param columns 1, // * @param i2cBus 39, // * @param i2cAddress 3, // * @param backlightBit 0, // * @param rsBit 1, // * @param rwBit 2, // * @param eBit 7, // * @param d7 6, // * @param d6 5, // * @param d5 4 // * @param d4 ); lcd.write(1, "test", LCDTextAlignment.ALIGN_CENTER); } }
This code for LCM1602 IIC V1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.