简体   繁体   中英

Java library import difficulty

I'm trying to compile a small test program I have written for a raspberry pi. The program makes use of the Pi4J library to control the piface add-on board.

What I have done so far is based on the following tutorial: http://www.savagehomeautomation.com/piface

While I can get the above example program to compile within my IDE after setting up the class paths I get compile errors with the one I have made and as far as I can tell the imports are set up in the same way.

It says that each of the following packages does not exist:

import java.io.IOException;
import com.pi4j.component.switches.SwitchListener;
import com.pi4j.component.switches.SwitchState;
import com.pi4j.component.switches.SwitchStateChangeEvent;
import com.pi4j.device.piface.PiFace;
import com.pi4j.device.piface.PiFaceLed;
import com.pi4j.device.piface.PiFaceRelay;
import com.pi4j.device.piface.PiFaceSwitch;
import com.pi4j.device.piface.impl.PiFaceDevice;
import com.pi4j.wiringpi.Spi;

I'm assuming that my problem is relatively simple but I don't really understand how import statements work and it's quite vague topic to search about. I have included some file paths if that helps.

This is where my project resides:

/home/pi/JBerries/relay

and this is where the pi4j library is:

/opt/pi4j

I hope the following image provides some of the information requested, note that the class paths are already set up: jBerries IDE截图

You need to set the CLASSPATH environment variable to /opt/pi4j or the jar file therein. WIthout this the compiler is unable to know where your libary is located and will give you the errors you describe.

If you're using a project in JBerries you need to configure the classpath for the project - the screenshot shows the classpath for single-file compilations only. To edit the project config right-click the root node in the project window and select properties.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM