cohenje
Posts: 1
Joined: Mon Dec 01, 2014 11:56 pm

pi4j -- Getting ClassNotFoundException on RaspiPin

Tue Dec 02, 2014 12:27 am

I'm trying to use pi4j for a simple blinking LED project. I'm getting a java.lang.NoClassDefFoundError: com/pi4j/io/gpio/RaspiPin in main caused by a java.lang.ClassNotFoundException: com.pi4j.io.gpio.RaspiPin

Any assistance greatly appreciated.

I believe I'm making the calls correctly:
DIO = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_04,"Pin 4", PinState.LOW);

Where DIO is a class attribute declared as:
protected GpioPinDigitalOutput DIO = null;

I'm new to maven. I tried to use the existing, online archive. Here's pom file (they won't let it come in as an attachment).
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.cohenje.blinky</groupId>
<artifactId>MvnBlinky</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>MvnBlinky</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>oss-snapshots-repo</id>
<name>Sonatype OSS Maven Repository</name>
<url>https://oss.sonatype.org/content/groups/public</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-core</artifactId>
<version>0.0.5</version>
<exclusions>
<exclusion>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-native</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<sourceDirectory>/home/pi/JavaBlinky/discreteIO/MvnBlinky/src/main/java</sourceDirectory>
<outputDirectory>/home/pi/JavaBlinky/discreteIO/MvnBlinky/target/classes</outputDirectory>
</build>
</project>


I'm also including the full class that contains the error:
package discreteIO;

import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalOutput;
import com.pi4j.io.gpio.PinState;
import com.pi4j.io.gpio.RaspiPin;

public class DiscreteOutput {
//attributes
protected String IOName;
protected DiscreteValueType DefaultVal = DiscreteValueType.OFF; //The basic default value
protected boolean InverseLogic = false; //determines if the discrete is inverse logic; 1=off
protected int pin = 0 ; //the number of the pin
protected GpioController gpio = null; //the reference to the controller
protected GpioPinDigitalOutput DIO = null; //the reference to the physical pin

//constructors
public DiscreteOutput () {
}

public DiscreteOutput (DiscreteValueType DefVal, boolean InvLogic, int IOPin){
DefaultVal = DefVal;
InverseLogic = InvLogic;
pin = IOPin;
}

public void Reset(){
//resets the output to its default value
Write(DefaultVal);
}

public void Write(DiscreteValueType val){
//writes the value out
//local value that gets written either ON (high) or OFF (low)
DiscreteValueType writeVal;
if (InverseLogic) {
if (DiscreteValueType.ON == val) {
writeVal = DiscreteValueType.OFF;
}else {
writeVal = DiscreteValueType.ON;
}
} else {
writeVal = val;
}
//write out writeVal to the pin
if (DiscreteValueType.ON == writeVal){
DIO.high();
} else {
DIO.low();
}
}


public void Setup(){
//used to set up the I/O
//set DIO to point at the pin
if (null != gpio) {
gpio = GpioFactory.getInstance();
}
switch (pin) {
case 0:
DIO = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_00);
break;
case 1:
DIO = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01);
break;
case 2:
DIO = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_02);
break;
case 3:
DIO = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_03);
break;
case 4:
GpioPinDigitalOutput localDIO = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_04,"Pin 4", PinState.LOW);
DIO = localDIO;
break;
case 5:
DIO = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_05);
break;
case 6:
DIO = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_06);
break;
case 7:
DIO = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_07);
break;
case 8:
DIO = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_08);
break;
case 9:
DIO = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_09);
break;
case 10:
DIO = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_10);
break;
case 11:
DIO = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_11);
break;
case 12:
DIO = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_12);
break;
case 13:
DIO = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_13);
break;
case 14:
DIO = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_14);
break;
case 15:
DIO = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_15);
break;
case 16:
DIO = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_16);
break;
case 17:
DIO = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_17);
break;
case 18:
DIO = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_18);
break;
case 19:
DIO = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_19);
break;
case 20:
DIO = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_20);
break;
}
}
}

User avatar
gpio
Posts: 26
Joined: Wed Dec 03, 2014 10:19 pm
Location: Gran Canaria :: Spain

Re: pi4j -- Getting ClassNotFoundException on RaspiPin

Sun Dec 07, 2014 8:57 am

Hello,

Your application is running on Raspberry Pi?

You tried this?

$ pi4j --run your_project

That added to the classpath, it seems that is what you are missing.

Regards.

Return to “Java”