• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

please clarify this error...unsupported exception.

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
{
}

}
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Mark Vedder
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the clarification Jim. I was not aware there was a change in the use of that term.
 
Let nothing stop you! Not even this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic