-1

I am trying to run everything from the linux command line to which I am relatively new too.

I am trying to compile a class which uses some external libraries and when i do javac classname.java i get warnings....

It is recommended that the compiler be upgraded.
warning: /opt/pi4j/lib/pi4j-core.jar(com/pi4j/io/gpio/GpioPinOutput.class): major version 51 is newer than 50, the highest major version supported by this compiler.

Even though it is just a warning - I have tried to then run java on the class file which results in

Exception in thread "main" java.lang.UnsupportedClassVersionError: com/pi4j/io/gpio/GpioFactory : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
    at ControlGpioExample.main(ControlGpioExample.java:9)

I searched stackoverflow and found a post suggesting to use cross compilation - which I have tried via

javac -target 1.6 ControlGpioExample.java 

How do I know which target to use? Do i just keep going through them all until it works?!

Thanks

Biscuit128
  • 5,218
  • 22
  • 89
  • 149

4 Answers4

2

It's not the code you're compiling that's the problem - it's the code you're compiling against, in pi4j-core.jar, which appears to have been built with Java 7.

I strongly suggest you upgrade the JDK, basically. Either that, or:

  • Find a version of pi4j which was built with Java 6
  • Rebuild it yourself
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
0

You're using Java 6 (version 50) to compile code that uses a library that has been compiled with Java 7 (version 51). Either upgrade your compiler or find a version of pi4j which was compiled with Java 6, and you should be good to go. Upgrading to JDK7 would be the best option.

As a reference, here are the version numbers and what they correspond to:

  • J2SE 7 = 51
  • J2SE 6.0 = 50
  • J2SE 5.0 = 49
  • JDK 1.4 = 48
  • JDK 1.3 = 47
  • JDK 1.2 = 46
  • JDK 1.1 = 45
Vivin Paliath
  • 94,126
  • 40
  • 223
  • 295
0

Please have a look at the pi4j (pi4j-native) build requirements. I took them from here

  • gcc 4.6.3 or newer (sudo apt-get install gcc)
  • git-core (sudo apt-get install git-core)
  • A working JDK (OpenJDK or Oracle JDK) (sudo apt-get install openjdk-7-jdk)
  • A valid defined JAVA_HOME environment variable
  • wiringPi source and platform compiled binary (...)

So, as the other answers already suggest, it would be best to upgrade to JDK 7.

Basically, pi4j may use some features available in JDK7 that your present JDK6-based compiler is not able to handle.

Community
  • 1
  • 1
Stefan Freitag
  • 3,578
  • 3
  • 26
  • 33
0

This issue will happen when you compile the Java code with higher version JDK and try to run the same with lower version of JDK. Do you know which version of Java are you using?

SarZ
  • 256
  • 2
  • 8