How To Resolve Java.Lang.Unsupportedclassversionerror Amongst Example
java.lang.UnsupportedClassVersionError is a quite mutual fault afterward NoClassDefFoundError or ClassNotFoundException they all seems to related to shape files but they all are dissimilar as well as at that spot crusade as well as resolution are different. In this coffee tutorial nosotros volition reckon what is UnsupportedClassVersionError in Java? Why UnsupportedClassVersionError comes inwards Java? What is shape file format as well as version numbers associated amongst it as well as in conclusion how to resolve UnsupportedClassVersionError in Java.
This article is inwards continuation of debugging tutorials similar How to remote debug Java computer program inwards Eclipse as well as 10 Java debugging tips inwards Eclipse. If you lot bring non read those article you lot may reveal them useful.
How to resolve UnsupportedClassVersionError inwards Java
What is UnSupportedClassVersionError inwards Java?
The Version of shape file is represented equally major_version.minor_version. This version is used to decide format of shape file inwards Java.
According to Java Virtual Machine specification, “A JVM implementation tin dismiss back upwards a shape file format of version v if as well as alone if v lies inwards about contiguous attain Mi.0 v Mj.m. Only Lord's Day tin dismiss specify what attain of versions a JVM implementation conforming to a sure enough unloosen score of the Java platform may support.” For example: JDK 1.2 supports shape file formats from version 45.0 to version 46.0 inclusive. So if a shape file has version 48.0 it agency that major version of shape file is "48" as well as fry version is "0", which tells us that JDK 1.4 has been used to compile as well as generate that shape file.
When UnSupportedClassVersionError inwards Java comes:
So directly nosotros got the theory behind shape file format as well as major as well as fry version of shape file inwards Java. Now a 1000000 dollar enquiry is when UnSupportedClassVersionError inwards Java does occur? precise answer of this is "When JVM tries to charge a shape as well as industrial plant life that shape file version is non supported it throws UnSupportedClassVersionError as well as it mostly 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 trial if you lot compile your coffee source file inwards JDK 1.5 as well as you lot volition endeavor to run it on JDK 1.4 you lot volition instruct fault "java.lang.UnsupportedClassVersionError: Bad version set out inwards .class file [at java.lang.ClassLoader.defineClass1(Native Method)]".But its of import to banking concern annotation is that vice-versa is non truthful "you tin dismiss compile your computer program inwards J2SE 1.4 as well as run on J2SE 1.5 as well as you lot volition non instruct whatsoever UnSupportedClassVersionError". When a higher JDK is used for compilation it creates shape file amongst higher version as well as when a lower JDK is used to run the computer program it industrial plant life that higher version of shape file non supported at JVM score as well as results inwards java.lang.UnsupportedClassVersionError.
How to ready UnSupportedClassVersionError
Now nosotros know the root crusade 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 you lot for which shape it’s coming. So if you lot are using multiple 3rd political party jars inwards your application you lot reveal that it comes at a detail business office when JVM tries to charge a shape from a detail jar. anyway nosotros all know that latest version of JDK is 1.6 as well as thus maximum version of shape file could last generated past times JDK 6, as well as thus past times using JDK half dozen nosotros tin dismiss solve UnSupportedClassVersionError, but many times its non tardily to only motion to higher JDK version. So I would suggest: 1) Find out due to which jounce or shape file this UnSupportedClassVersionError is coming?
2) Try to compile source code of that jounce amongst the JDK version you lot are using to run your program, if source is available.
3) If you lot don't bring source endeavor to reveal the compatible version of that library.
4) Increase the JRE version you lot are using to run your program.
You tin dismiss become past times whatsoever approach to resolve UnSupportedClassVersionError based upon your need. Generally a higher JVM version is ok as well as does non crusade whatsoever employment unless the shape file format is quite onetime as well as no to a greater extent than supported past times Lord's Day inwards higher JVMs. The best way to bargain amongst UnSupportedClassVersionError inwards Java is to purpose same version or JDK as well as JRE for compiling as well as running your program.
Example of UnSupportedClassVersionError inwards Java
You tin dismiss easily reproduce UnSupportedClassVersionError past times using javac of higher JDK as well as "java" from lower Java version. Let’s reckon about 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 past times JDK 1.5, as well as thus these volition "java.lang.UnsupportedClassVersionError” volition come upwards if JVM used to run this computer program is lower than Java 1.5.
2) Java.lang.UnsupportedClassVersionError: Bad version set out inwards .class file
3) java.lang.unsupportedclassversionerror unsupported classversion 50.0
==> Compile inwards JDK 1.6 as well as running on lower version than Java 6.
4) java.lang.unsupportedclassversionerror unsupported classversion 49.0
==> compiled inwards Java v as well as running on lower JVM than JDK 5.
5) java.lang.unsupportedclassversionerror bad version set out inwards eclipse.
==> Most of us purpose eclipse for edifice as well as running projection about of us too purpose emmet for edifice project. In eclipse at that spot is about setting related to coffee source version which if you lot got wrong tin dismiss trial inwards "java.lang.unsupportedclassversionerror bad version number". as well as thus brand sure enough you lot bring right configuration. For trial if you lot compile amongst source compatible 1.6 you lot involve JRE half dozen to execute the program. To banking concern fit the compiler setting inwards eclipse become to project ==>Properties==>Java Compiler equally shown inwards image
Important yell for close UnSupportedClassVersionError inwards Java:
1) If you lot run into UnSupportedClassVersionError, banking concern fit the JRE version you lot are using to run computer program as well as switch to higher version for quick solution.2) java.lang.UnsupportedClassVersionError is derived from java.lang.LinkageError, as well as thus it volition non last detected inwards compile fourth dimension as well as it volition alone come upwards on runtime, just when JVM tries to charge a class.
3) Class file format which is identified using major version as well as fry version. Class file format is assigned when you lot compile source file as well as its depends on JDK version used to compile.
4) Its ever best practise to purpose same version of coffee for compilation as well as execution to avoid whatsoever endangerment of UnSupportedClassVersionError.
5) UnSupportedClassVersionError is non related to java classpath , as well as thus don't confuse this amongst NoClassDefFoundError or ClassNotFoundException.
Major Class Versions of Various JDK
Following are the major version of class file format inwards criterion 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 dismiss too instruct version of "javac" (used for compilation) as well as 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 you lot tin dismiss position your JDK version based on shape file format version whenever you lot reckon java.lang.UnsupportedClassVersionError :)
Further Learning
Complete Java Masterclass
how coffee hashmap works, why String is immutable inwards java, why await as well as notify needs to telephone telephone from synchronized context interesting.
Belum ada Komentar untuk "How To Resolve Java.Lang.Unsupportedclassversionerror Amongst Example"
Posting Komentar