aspose file tools*
The moose likes Beginning Java and the fly likes please clarify this error...unsupported exception. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "please clarify this error...unsupported exception." Watch "please clarify this error...unsupported exception." New topic
Author

please clarify this error...unsupported exception.

suresh sai
Ranch Hand

Joined: Jul 16, 2007
Posts: 62
Hi,
please clarify how to overcome by this type of exception .
when I run my java class ,it compiles fine.But it shows the runtime exception as unsupported class error.I am using jdk1.5.0_06

D:\sureshsai>javac NewClass.java

D:\sureshsai>java NewClass
Exception in thread "main" java.lang.UnsupportedClassVersionError: NewClass (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)

and also please tell me ,What is meant by a top level class?
here in this code,iam getting a compile time error.


protected class AnotherClass
{


}


class MyClass
{
public static void main(String l[])
{
System.out.println("hello");

}

}


D:\sureshsai>javac MyClass.java
MyClass.java:1: modifier protected not allowed here
protected class AnotherClass
John Dell'Oso
Ranch Hand

Joined: Apr 08, 2004
Posts: 130
Hello,

You've compiled the class with JDK 1.5.x and are probably trying to run it with a JVM 1.4 version. Without knowing your environment, I would only be guessing where it's finding a reference to this java runtime.

Regards,
JD
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

Exception in thread "main" java.lang.UnsupportedClassVersionError: NewClass (Unsupported major.minor version 49.0)

This exception means that a java class you are trying to run was compiled using a newer version of java then what you are trying to run it under. Based n the version number (49.0) it tells me that the class was compiled under Java 1.5, but is trying to be run under Java 1.4.

The most likely issue is a PATH issue. When you compiled, the javac command was found in your 1.5 installation's bin directory. But when you go to run it, it ran against a 1.4 installation on your machine. Since both java and javac reside in the same bin directory of the JDK, this indicates that the bin directory of a JRE only install of Java 1.4 is in your PATH environment variable before your 1.5 JDK's bin directory.

Take a look at your PATH environment variable, and update it so the 1.5 bin is in it. You probably want to remove your 1.4 bin directory, but make sure some Java version is in it.
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

As for this question:

and also please tell me ,What is meant by a top level class?

A basic definition of a top level class can be found at http://mindprod.com/jgloss/toplevel.html.
You can also read the JavaWorld article Static class declarations. While not directly about top level classes, it discusses various types of classes, including top-level. You can also look at http://www.adp-gmbh.ch/java/language/classes.html which gives a very nice summary of different types of classes.

I hope that helps. By the way, I found those three references, and more, using a Goggle search of "Java Top Level class"

After reading those articles, you should be able to determine why you are getting the compile error. But here's a hint... even if a bedroom door is unlocked and open to the public, no one can get to it if the house's door is locked and protected from access. This is because one must enter the house before he can enter the bedroom. Think about how that relates to your declared classes and methods. If you still are having trouble figuring out the your issue, post another question, and someone can help you.
suresh sai
Ranch Hand

Joined: Jul 16, 2007
Posts: 62
Thank you John and Mark,

Thank you for giving such a help.But iam still unable to understand what is a top level class ?Otherwise ,Shall we come in another way, that is ,What is not a top level class? or How can we decide whether a class is top level or not? Iam very much thank full if,you explain with examples.
Pushpalatha manavalan
Greenhorn

Joined: Jul 28, 2007
Posts: 1
top level classes are classes which are not defined inside any other class (non inner class)

class A // top level class
{

class B // inner class
{
}

}
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Chinna, several of the articles Mark found contain older terminology which is now out of date. When Sun first introduced nested classes, they included the confusing term "top-level nested class" to refer to static member classes. These are classes which are nested but share many other atributes with "regular" top-level classes. However this terminolgy was, fortunately, dropped when the JLS 2nd edition came out. Now "top-level" always means a class that is not nested in any way. When you encounter books, articles, or people who refer to top-level nested classes, I suggest you either (a) ignore them, or (b) just pretend they said "static nested classes" instead.


"I'm not back." - Bill Harding, Twister
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

Thanks for the clarification Jim. I was not aware there was a change in the use of that term.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: please clarify this error...unsupported exception.