0

I have absolutely no idea what has gone wrong here. One day I have a perfectly working system using rosjava, and then the next morning I am getting this error:

Exception in thread "main" java.lang.UnsupportedClassVersionError: org/ros/RosRun : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:643)
    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:323)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
Could not find the main class: org.ros.RosRun. Program will exit.

I haven't changed any code, updated any files, nothing. This just happened. Does anyone have any idea why?

Things I have tried: After doing research on errors similar to this, I found out that it occurs when java versions do not match. 51 is Java 1.7. So I checked out my own java version with:

java -version

and got:

java version "1.6.0_33"
OpenJDK Runtime Environment (IcedTea6 1.13.5) (6b33-1.13.5-1ubuntu0.12.04)
OpenJDK 64-Bit Server VM (build 23.25-b01, mixed mode)

So I am running java 1.6. Makes sense, the error is telling me RosRun is 1.7. Let me check.

$ file RosRun.class 
RosRun.class: compiled Java class data, version 50.0 (Java 1.6)

Well thats not the case. That means my code must be compiling in 1.7. Let me check:

$ file project/build/classes/main/com/github/hsmrs_gui/project/GuiNode.class 
project/build/classes/main/com/github/hsmrs_gui/project/GuiNode.class: compiled Java class data, version 50.0 (Java 1.6)

I'm at a loss. Can anyone help?

RoboCop87
  • 825
  • 1
  • 8
  • 21
  • Possibly another version of `RosRun` is hiding in your classpath, perhaps in a JAR, perhaps in some other path. Can you scan your classpath and check? – RealSkeptic Feb 25 '15 at 19:19
  • If I do $locate RosRun I only get a hit on the RosRun.class, .java, and a RosRunException.class and .java. I'm not sure how else to check besides this. – RoboCop87 Feb 25 '15 at 19:25
  • Any jars in your classpath? Also, are you absolutely sure that the `java` you run from command line is the same `java` used to run your application? – RealSkeptic Feb 25 '15 at 19:49
  • I fixed it, but I'm not a bit confused as to how my java command line could be different than any other java on my computer. Isn't it a system wide thing? – RoboCop87 Feb 25 '15 at 19:52
  • 2
    You can have several installations of java on the same machine. Sometimes you have a separate JDK and JRE, and the default `java` command is that of the JRE, while the one used by your IDE or maven is the JDK's. – RealSkeptic Feb 25 '15 at 20:00
  • Does this answer your question? [How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version](https://stackoverflow.com/questions/10382929/how-to-fix-java-lang-unsupportedclassversionerror-unsupported-major-minor-versi) – 9ilsdx 9rvj 0lo Jun 07 '21 at 11:15

1 Answers1

-1

I ran $sudo apt-get upgrade which turned the output of $java -version into:

java version "1.7.0_76"
Java(TM) SE Runtime Environment (build 1.7.0_76-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.76-b04, mixed mode)

and then reran my code. It works now. I still have no idea why this broke in the first place though.

RoboCop87
  • 825
  • 1
  • 8
  • 21