J'essaye de faire un simple exemple Xbee sur mon travail Raspberry Pi 3, en utilisant le XBee Java Lib et son tutoriel, mais je veux l'exécuter avant de le transformer en un fichier .jar. Je veux juste l'exécuter comme un fichier .class, très simple, après que je veux l'importer dans un autre projet. (Je ne suis pas bon avec Java, car il est possible de voir) Après avoir compilé j'ai essayé de l'exécuter comme:XBee utilisant Java Lib sur Raspberry Pi
java -cp $XBJL_CLASS_PATH:. com.digi.xbee.example.MainApp
mon echo $XBJL_CLASS_PATH
est:
libs/xbee-java-library-1.2.1.jar:libs/rxtx-2.2.jar:libs/slf4j-api-1.7.12.jar:libs/slf4j-nop-1.7.12.jar:libs/android-sdk-5.1.1.jar:libs/android-sdk-addon-3.jar
Ce qui signifie que tous les .jar à avaiable utiliser à partir du XBee Java Lib.
Il n'a pas work.I've aussi essayé simplement:
java com.digi.xbee.example.MainApp
Et je suis toujours obtenir la même erreur:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: com/digi/xbee/api/XBeeDevice
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: com.digi.xbee.api.XBeeDevice
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)
... 7 more
Quelqu'un sait-il ce qui pourrait être happenning? Il dit que je n'ai pas importé le XBeeDevice, ce que j'ai fait, en important le libs/xbee-java-library-1.2.1.jar
.
PS: Le code commence par ceci:
package com.digi.xbee.example;
import com.digi.xbee.api.WiFiDevice;
import com.digi.xbee.api.XBeeDevice;
import com.digi.xbee.api.exceptions.XBeeException;
import com.digi.xbee.api.models.XBeeProtocol;
public class MainApp {
/* Constants */
// TODO Replace with the port where your sender module is connected to.
private static final String PORT = "/dev/ttyAMA0/";
// TODO Replace with the baud rate of your sender module.
private static final int BAUD_RATE = 9600;
private static final String DATA_TO_SEND = "Hello XBee World!";
public static void main(String[] args) {
XBeeDevice myDevice = new XBeeDevice(PORT, BAUD_RATE);
byte[] dataToSend = DATA_TO_SEND.getBytes();
try {
myDevice.open();
System.out.format("Sending broadcast data: '%s'", new String(dataToSend));
if (myDevice.getXBeeProtocol() == XBeeProtocol.XBEE_WIFI) {
myDevice.close();
myDevice = new WiFiDevice(PORT, BAUD_RATE);
myDevice.open();
((WiFiDevice)myDevice).sendBroadcastIPData(0x2616, dataToSend);
} else
myDevice.sendBroadcastData(dataToSend);
System.out.println(" >> Success");
} catch (Exception e) {
System.out.println(" >> Error");
e.printStackTrace();
System.exit(1);
}
finally {
myDevice.close();
}
}
}
Merci à l'avance.