This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Has my compiler lost it?  RSS feed

 
Tontang Bei
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Nothing Special about the above code. I saved and compiled the code below as DateForm.java. I can see the class file that was created as a result of compilation in the folder that I saved this code. But when I run it heres what I get:
Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
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.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 java.lang.ClassLoader.loadClassInternal(Unknown Source)

This is happening on both my laptop and my desktop. Any help is appreciated
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you look at the creation date of the .class file, does it match with when you compiled it?

Also you need to look at the other directories in your CLASSPATH to see if there is another DateForm.class file that it might find.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To compile DateForm.java to produce DateForm.class, you type

javac DateForm.java

To run the class, you type

java DateForm

Is this what you're doing? Since this is happening on two machines, one likely explanation is that you're sending non-class files to the JVM.
 
Tontang Bei
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im typing the appropriate commands. Ive tried deleting the class files and compiling again but again same exceptions. Ive checked my paths and nothing is conflicting. I dont get it. Is this happening on anyone else's computer too?
 
Paul Clapham
Sheriff
Posts: 22503
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds to me like you are compiling your class using Java version N and then trying to run it using Java version N-1.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have multiple versions of Java installed? What output do you get if you type in these commands:

java -version

javac -version
 
Tontang Bei
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul, Jesper. you guys have got it right.

When I type: java -version it says:

java version "1.5.0_11"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03)
Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode)

When I type: javac -version it says:
javac 1.6.0

Should I update the runtime environment?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can compile for an older version by using the "-source" and "-target" switches, e.g.

javac -source 1.5 -target 1.5 DateForm.java

That only works if the source actually is for Java 1.5 (i.e., does not contain any Java 6 features).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!