How To Resolve Java.Lang.Unsupportedclassversionerror Alongside Example
java.lang.UnsupportedClassVersionError is a quite mutual fault later on NoClassDefFoundError or ClassNotFoundException they all seems to related to degree files but they all are unlike in addition to in that location displace in addition to resolution are different. In this coffee tutorial nosotros volition catch what is UnsupportedClassVersionError in Java? Why UnsupportedClassVersionError comes inwards Java? What is degree file format in addition to version numbers associated amongst it in addition to lastly how to resolve UnsupportedClassVersionError in Java.
This article is inwards continuation of debugging tutorials similar How to remote debug Java programme inwards Eclipse in addition to 10 Java debugging tips inwards Eclipse. If yous accept non read those article yous may discover them useful.
How to resolve UnsupportedClassVersionError inwards Java
What is UnSupportedClassVersionError inwards Java?
The Version of degree file is represented equally major_version.minor_version. This version is used to decide format of degree file inwards Java.
According to Java Virtual Machine specification, “A JVM implementation tin back upwards a degree file format of version v if in addition to entirely if v lies inwards unopen to contiguous make Mi.0 v Mj.m. Only Sunday tin specify what make of versions a JVM implementation conforming to a surely free flat of the Java platform may support.” For example: JDK 1.2 supports degree file formats from version 45.0 to version 46.0 inclusive. So if a degree file has version 48.0 it agency that major version of degree file is "48" in addition to fry version is "0", which tells us that JDK 1.4 has been used to compile in addition to generate that degree file.
When UnSupportedClassVersionError inwards Java comes:
So directly nosotros got the theory behind degree file format in addition to major in addition to fry version of degree file inwards Java. Now a 1 thou k dollar query is when UnSupportedClassVersionError inwards Java does occur? precise answer of this is "When JVM tries to charge a degree in addition to institute that degree file version is non supported it throws UnSupportedClassVersionError in addition to it to a greater extent than ofttimes than non occurs if a higher JDK version is used to compile the source file and a lower JDK version is used to run the program. for instance if yous compile your coffee source file inwards JDK 1.5 in addition to yous volition endeavour to run it on JDK 1.4 yous volition larn fault "java.lang.UnsupportedClassVersionError: Bad version expose inwards .class file [at java.lang.ClassLoader.defineClass1(Native Method)]".But its of import to banknote is that vice-versa is non truthful "you tin compile your programme inwards J2SE 1.4 in addition to run on J2SE 1.5 in addition to yous volition non larn whatsoever UnSupportedClassVersionError". When a higher JDK is used for compilation it creates degree file amongst higher version in addition to when a lower JDK is used to run the programme it institute that higher version of degree file non supported at JVM flat in addition to results inwards java.lang.UnsupportedClassVersionError.
How to create UnSupportedClassVersionError
Now nosotros know the root displace of UnSupportedClassVersionError that nosotros are using a lower JVM for running the program. But major employment is that stack describe of UnSupportedClassVersionError volition non say yous for which degree it’s coming. So if yous are using multiple tertiary political party jars inwards your application yous discover that it comes at a detail purpose when JVM tries to charge a degree from a detail jar. anyway nosotros all know that latest version of JDK is 1.6 in addition to therefore maximum version of degree file could live generated yesteryear JDK 6, in addition to therefore yesteryear using JDK vi nosotros tin solve UnSupportedClassVersionError, but many times its non tardily to simply displace to higher JDK version. So I would suggest: 1) Find out due to which jounce or degree file this UnSupportedClassVersionError is coming?
2) Try to compile source code of that jounce amongst the JDK version yous are using to run your program, if source is available.
3) If yous don't accept source endeavour to discover the compatible version of that library.
4) Increase the JRE version yous are using to run your program.
You tin become yesteryear whatsoever approach to resolve UnSupportedClassVersionError based upon your need. Generally a higher JVM version is ok in addition to does non displace whatsoever employment unless the degree file format is quite quondam in addition to no to a greater extent than supported yesteryear Sunday inwards higher JVMs. The best way to bargain amongst UnSupportedClassVersionError inwards Java is to utilisation same version or JDK in addition to JRE for compiling in addition to running your program.
Example of UnSupportedClassVersionError inwards Java
You tin easily reproduce UnSupportedClassVersionError yesteryear using javac of higher JDK in addition to "java" from lower Java version. Let’s catch unopen to of examples of UnSupportedClassVersionError inwards Java:1) java.lang.UnsupportedClassVersionError: EquityTradingManager (Unsupported major.minor version 49.0)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
==>Since nosotros know that major version 49 is supported yesteryear JDK 1.5, in addition to therefore these volition "java.lang.UnsupportedClassVersionError” volition come upwards if JVM used to run this programme is lower than Java 1.5.
2) Java.lang.UnsupportedClassVersionError: Bad version expose inwards .class file
3) java.lang.unsupportedclassversionerror unsupported classversion 50.0
==> Compile inwards JDK 1.6 in addition to running on lower version than Java 6.
4) java.lang.unsupportedclassversionerror unsupported classversion 49.0
==> compiled inwards Java v in addition to running on lower JVM than JDK 5.
5) java.lang.unsupportedclassversionerror bad version expose inwards eclipse.
==> Most of us utilisation eclipse for edifice in addition to running projection unopen to of us likewise utilisation emmet for edifice project. In eclipse in that location is unopen to setting related to coffee source version which if yous got wrong tin effect inwards "java.lang.unsupportedclassversionerror bad version number". in addition to therefore brand surely yous accept right configuration. For instance if yous compile amongst source compatible 1.6 yous require JRE vi to execute the program. To banking concern tally the compiler setting inwards eclipse become to project ==>Properties==>Java Compiler equally shown inwards image
Important indicate virtually UnSupportedClassVersionError inwards Java:
1) If yous come across UnSupportedClassVersionError, banking concern tally the JRE version yous are using to run programme in addition to switch to higher version for quick solution.2) java.lang.UnsupportedClassVersionError is derived from java.lang.LinkageError, in addition to therefore it volition non live detected inwards compile fourth dimension in addition to it volition entirely come upwards on runtime, exactly when JVM tries to charge a class.
3) Class file format which is identified using major version in addition to fry version. Class file format is assigned when yous compile source file in addition to its depends on JDK version used to compile.
4) Its ever best exercise to utilisation same version of coffee for compilation in addition to execution to avoid whatsoever peril of UnSupportedClassVersionError.
5) UnSupportedClassVersionError is non related to java classpath , in addition to therefore don't confuse this amongst NoClassDefFoundError or ClassNotFoundException.
Major Class Versions of Various JDK
Following are the major version of class file format inwards measure JDK environment.JDK 1.1 = 45
JDK 1.2 = 46
JDK 1.3 = 47
JDK 1.4 = 48
JDK 1.5 = 49
JDK 1.6 = 50
You tin likewise larn version of "javac" (used for compilation) in addition to version of "java" (used for execution) equally below
C:\equity trading\stocks>javac -version
javac 1.6.0-beta2
C:\equity trading\stocks>java -version
java version "1.6.0-beta2"
Java(TM) SE Runtime Environment (build 1.6.0-beta2-b86)
Java HotSpot(TM) Client VM (build 1.6.0-beta2-b86, mixed mode, sharing)
Now yous tin position your JDK version based on degree file format version whenever yous catch java.lang.UnsupportedClassVersionError :)
Further Learning
Complete Java Masterclass
how coffee hashmap works, why String is immutable inwards java, why aspect in addition to notify needs to telephone telephone from synchronized context interesting.
0 Response to "How To Resolve Java.Lang.Unsupportedclassversionerror Alongside Example"
Post a Comment