• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

UnsupportedClassVersionError exception?

 
Greenhorn
Posts: 12
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am reading the Head First Java book, and when I got to the 12th chapter there was an animation code that was supposed to show an oval moving across a JPanel. However, when I typed the code in it compiled but threw an exception when I tried to run it. I thought I maybe missed something out when typing and went to the site that has the original source code and just pasted it in and it was the same result. Anyone knows what the problem is?
Here's the code:


And here's the output:
 
Bartender
Posts: 2230
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It worked fine when I compiled and ran it.
So, maybe you have some old binaries in your classpath. Delete them all and recompile.

By the way, please post text not images.
PostTextNotScreenshots (read this)
 
Marko Matosevic
Greenhorn
Posts: 12
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wasn't able to run it, just compile it. Running it gives an exception.
I put the .java file in an empty folder and recompiled and it was still the same problem.
Sorry about the screenshot, I didn't know how to do the copying from Console2 but I got it now.


Exception in thread "main" java.lang.UnsupportedClassVersionError: SimpleAnimation :
Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

 
Rancher
Posts: 4614
47
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are compiling using one version of Java and executing using an earlier version.
Do:
javac -version
AND:
java -version

That should tell you at least what the difference is.
Then you'll probably need to hunt in your PATH to find out why it's picking two different ones.
 
Paweł Baczyński
Bartender
Posts: 2230
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have classpath variable set to anything?

Execute echo %classpath% and post the result.
 
Marko Matosevic
Greenhorn
Posts: 12
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Output: %classpath%
I guess that means it's empty, eh?
Was I supposed to set that? Because all of the programs before this one worked perfectly.
 
Marko Matosevic
Greenhorn
Posts: 12
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:You are compiling using one version of Java and executing using an earlier version.
Do:
javac -version
AND:
java -version

That should tell you at least what the difference is.
Then you'll probably need to hunt in your PATH to find out why it's picking two different ones.



javac version: javac 1.8.0_11
java version: "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) Client VM (build 24.65-b04, mixed mode, sharing)
 
Paweł Baczyński
Bartender
Posts: 2230
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Marko Matosevic wrote:Was I supposed to set that? Because all of the programs before this one worked perfectly.


No, do not set it. You don't need it. I requested this to ensure that you have not set it .

javac version: javac 1.8.0_11
java version: "1.7.0_67"



You can see here that you are compiling with version 1.8 but running with 1.7, thus the exception.
 
Marko Matosevic
Greenhorn
Posts: 12
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paweł Baczyński wrote:
You can see here that you are compiling with version 1.8 but running with 1.7, thus the exception.


So, I need to update the JDK or the JRE?
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adjust the PATH variable so that it points to the JDK's "bin" directory. Apparently it points to both JRE 7 and JDK 8, which causes the problem. Or you can uninstall JRE 7, assuming that don't need since you have JDK 8 installed.
 
Marko Matosevic
Greenhorn
Posts: 12
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. There was some folder with shortcuts of java.exe and other stuff in the PATH, that was probably automatically created by installing the old JRE. I deleted it and pointed the JDK path to the correct bin folder and it worked.
Thanks for the help.
 
Marshal
Posts: 69837
278
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can get this problem if you add the PATH to the new JDK installation later than the PATH to an old JRE installation.
 
Fire me boy! Cool, soothing, shameless self promotion:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic