your libary does not work

210 views
Skip to first unread message

pcmadn...@gmail.com

unread,
Jul 30, 2017, 7:09:39 PM7/30/17
to Pi4J
clean install used you example build 

error 


pi@raspberrypi:/opt/pi4j/examples $ sudo java GpioOutputExample 
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: com/pi4j/platform/PlatformAlreadyAssignedException
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.pi4j.platform.PlatformAlreadyAssignedException
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

Harald Sattmann

unread,
Jul 31, 2017, 7:50:09 AM7/31/17
to Pi4J
Hi
Are you SUDO

pcmadn...@gmail.com

unread,
Jul 31, 2017, 3:26:48 PM7/31/17
to Pi4J
indeed see my dump from console

Raffy Ibasco

unread,
Aug 1, 2017, 7:10:39 AM8/1/17
to Pi4J

First of all, it DOES work. 

Secondly, Is this your first time using Java?  The problem is pretty obvious just by looking at the stack trace... You are trying to run the program without even specifying the classpath entries. I suggest  you run it with the built-in utility script instead. 

# pi4j -r GpioOutputExample

pcmadn...@gmail.com

unread,
Aug 1, 2017, 1:26:25 PM8/1/17
to Pi4J
thats what i did and i been using java for many years

Raffy Ibasco

unread,
Aug 2, 2017, 5:17:46 AM8/2/17
to Pi4J
From the console dump you posted above, it showed that you did a

sudo java GpioOutputExample

 instead of 

pi4j -r <example>.java

pcmadn...@gmail.com

unread,
Aug 2, 2017, 4:35:27 PM8/2/17
to Pi4J
is there a way and can use java command nativly with your libary

Robert Savage

unread,
Aug 2, 2017, 4:40:30 PM8/2/17
to Pi4J
Sure, take a loot at this example

At the bottom of the page there is a section on EXECUTING the sample code using the java command line. 

Note that the java command line must include the classpath to find the Pi4J libraries on your system.
javac -classpath .:classes:/opt/pi4j/lib/'*' -d . ControlGpioExample.java

Thanks, Robert

pcmadn...@gmail.com

unread,
Aug 2, 2017, 6:15:01 PM8/2/17
to Pi4J
pi@raspberrypi:/opt/pi4j/examples $ sudo pi4j GpioOutputExample + java -classpath '.:classes:*:classes:/opt/pi4j/lib/*' GpioOutputExample

************************************************************
************************************************************

                  <-- The Pi4J Project -->                  
                     GPIO Output Example                    

************************************************************
************************************************************

------------------------------
|    PRESS CTRL-C TO EXIT    |
------------------------------

Unable to determine hardware version. I see: Hardware : BCM2835
,
 - expecting BCM2708 or BCM2709.
If this is a genuine Raspberry Pi then please report this
to proj...@drogon.net. If this is not a Raspberry Pi then you
are on your own as wiringPi is designed to support the
Raspberry Pi ONLY.

Robert Savage

unread,
Aug 2, 2017, 7:23:25 PM8/2/17
to Pi4J
Which version of Pi4J do you have installed?

pi4j --version

You may need to upgrade to the latest 1.2-SNAPSHOT version.  


On Wednesday, August 2, 2017 at 6:15:01 PM UTC-4, pcmadn...@gmail.com wrote:
pi@raspberrypi:/opt/pi4j/examples $ sudo pi4j GpioOutputExample + java -classpath '.:classes:*:classes:/opt/pi4j/lib/*' GpioOutputExample

************************************************************
************************************************************

                  <-- The Pi4J Project -->                  
                     GPIO Output Example                    

************************************************************
************************************************************

------------------------------
|    PRESS CTRL-C TO EXIT    |
------------------------------

Unable to determine hardware version. I see: Hardware : BCM2835
,
 - expecting BCM2708 or BCM2709.
If this is a genuine Raspberry Pi then please report this
to .... If this is not a Raspberry Pi then you

Andrew Chandler

unread,
Aug 3, 2017, 8:25:53 AM8/3/17
to Pi4J
The latest kernel update changed how the CPU identifies itself. Wiring pi which pi4j relies on is hard coded to only support real raspberry pi so it checks that identifier. They have fixed that check I believe but it does require the update.

pcmadn...@gmail.com

unread,
Aug 3, 2017, 10:50:56 AM8/3/17
to Pi4J
this was a fresh install  a few days ago and also updates as well to get this working 

Wiring pi works fine its your libary that produces the error 

Robert Savage

unread,
Aug 5, 2017, 10:55:45 AM8/5/17
to Pi4J

Please see this thread:

You either need to use 1.2-SNAPSHOT builds or use the dynamic linking option.
Reply all
Reply to author
Forward
0 new messages