• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception in thread "main" java. lang. UnsupportedClassVersion Error:

 
eric scott
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I compile my application, but when I run the application I get this message,"
C:\>javac Ch2Birthdate.java

C:\>java Ch2Birthdate
Exception in thread "main" java.lang.UnsupportedClassVersionError: Ch2Birthdate
(Unsupported major.minor version 49.0)
at java.lang.ClassLoader.defineClass0(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)

C:\>

Now here is my code for the application

import javax.swing.*;
import java.util.*;
import java.text.*;


class Ch2Birthdate{

public static void main(String [] args){

String Input;

SimpleDateFormat sdf;


Input = JOptionPane.showInputDialog(null, "What is your birthdate?");
java.util.Date bdate = java.sql.Date.valueOf(Input);



sdf = new SimpleDateFormat("EEEE");

JOptionPane.showMessageDialog(null, "The day of your Birthday is: " + sdf.format(bdate));

}
}

Any advice is ok, thanks.
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
possible reasons -
1. u have 2 versions of jdk in ur path
2. You compiled using one version of jdk and try to run the program using some other version.

tx,
ram.
 
eric scott
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ram, thanks for the advice.
I checked my path, and there was other things in there.
So I cut everything out except C:\Program Files\Java\jdk1.5.0_01\bin.
I tried to run the application again, and I got the same error.

Next, I checked my java runtime settings. The path for user is
"C:\Program Files\Java\jre1.5.0-01\bin\javaw.exe",
The path for the system is the exact same.

I also have oracle, and jre1.4 installed on my computer if this matters.

Your advice is appreciated,
Thanks,
Eric
 
David Harkness
Ranch Hand
Posts: 1646
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps try running both javac and java by specifying the full path to both to make absolutely sure you know which is running. Also, you can do "java -version" and "javac -version" (two dashes? I don't ermember).

On a side note, you should get into the habit of always specifying a package for every class. The first non-comment/blank line should beYou'll need to create a directory structure that matches it and put your source file into it. You still issue your compile/run commands from the directory that contains the root package.

Since you're doing this in the root of your C drive, let's use "test" as the package. Create c:\test and put Ch2Birthdate.java into it. Addto the top of the file. Then compile and run usingI don't think that's the issue here, but it's still a good practice. For one thing, you cannot import a class that's ni the default package.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remove java.exe and javaw.exe from your windows installation directories.
Not all JVM installers properly update those under all conditions, leading old versions to be used when trying to execute Java programs.
But as there's no javac.exe there that one will get called from the directory you installed the JDK to.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Despite the error message having the word "thread" in it, this is not a thread-related problem. I'm moving this post to our Java beginner's forum.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic