[at java.lang.ClassLoader.defineClass1(Native Method)]
is an error that you may face in running a compiled java class file.
So as you can see from the stack trace, a class has not been loaded. But which class? The problem is this error message does not show the name of the failed .class, isn't it?
No, it is not. This error is caused when you compile a .java file with one version of JDK and running the .class file with a different version of JVM.
Confused? You may say; same version is not required to compile and run.
Yes, that is true. But you can not run .class files that are compiled with a newer version than the JVM.
Say;
javac (compile) - version: XIf X is newer than Y; then you may face this issue at runtime.
java (run) - version: Y
Now you know how to solve this issue, isn't it?
I tried 2 run some class files on java 1.5 I received from a friend and faced this error. Thanks for pointing the solution.
ReplyDeleteIt's crystal clear explanation. bunch of thanks Kamal.
ReplyDeleteThanks Kamal! Your post helped me.
ReplyDeleteDear Friend im facing the same problem but as u explaned i dont know how to use these commands plz help
ReplyDeleteHello friend,
ReplyDeletePlease check the versions of javac and java on your computer and post them here, then we'll create the required commands.
Wow cool
ReplyDeleteI can fix my problem by you posted
how is it that i remember being able to issue a "javac -version" before that worked, but now i can't figure out how to check my compiler version?
ReplyDeletejava -version (always works)
javac -version (now never works)
darksalmon
java version "1.6.0_12"
ReplyDeleteJava(TM) SE Runtime Environment (build 1.6.0_12-b04)
Java HotSpot(TM) Client VM (build 11.2-b01, mixed mode, sharing)
javac 1.6.0_12
I got the versions as above, but still getting this error. I have tried compiling it with or without -cp option, but it is still failing to run. I am able to get this to work from another workstation. Can you please help?
im facing the same problem but when i installed 1.5 it didnt showed any error but at run time it is showing the error
ReplyDeleteand java -version is showing 1.3.1 version
i installed latest 1.6 jvm and jre. javac -version is showing 1.6 but java -version is still showing 1.3 may be older version is not unistalled properly. help me
ReplyDeleteHi Satyam,
ReplyDeleteBest thing to resolve this would be, first remove all jre/jdk installations. (Better not to install two different versions on one machine.)
Then check for versions of both. That way you will be able to resolve this issue.
I am getting this error for groovy 1.6.0.
ReplyDeletejava.lang.UnsupportedClassVersionError: org/codehaus/groovy/tools/GroovyStarter (Unsupported major.minor version 49.0)
and my java -version is java version "1.6.0_11"
Any thoughts?
I think 49.0 => Java 1.5 ... are you sure all were recompiled?
ReplyDeleteDoesn't it identify the bad class file?
Thanks!
ReplyDeletethanks for the tips.
ReplyDeleteI have the same problem. But i have java version 1.5.0_21 and jvm is the same but in eclipse when i start tomcat this error happens.
ReplyDeleteAny idea?
I have check everything related to java so all is pointing to this version
Thanks in advance
// Tomcat and java version 1.5.0_21
ReplyDeleteCan you try starting Tomcat without the projects that you have deployed there? Then you will be able to locate the web application that causes this error.
Loud and clear..Thank you
ReplyDeleteThankyou yaar!
ReplyDeleteIf you get this in ECLIPSE. Look at the javac compliance under Windows->Preferences->Java->Compiler and make sure its the same as Eclipse's default JRE version.
ReplyDeleteThis was driving me nuts - until I saw my Eclipse JRE was 1.5 and this setting was at 1.6!!!!
thank you for the post I find it usefull.
ReplyDeleteI find that a few days before I had installed Zend Studio on Windows 7, while replacing my JRE becoz Zend studio does't work well on this window and currently this is the one way to get it work well on Win7.
Good Solution
ReplyDeleteThank U very much dude.. Ur explantion was very clear..
ReplyDeleteThe problem is that versions of compilation (javac) and run (java) must be the same, but not necessarily in your PC. The JDBC connection is to be compatible with our PC.
ReplyDeleteSo the solution is to find the appropriate JDBC.
Of course the error message should tell me the class. In my case I have both Java 1.5 set in the Eclipse project, and the settings show that 1.5 class files are being built. I also am running with JDK1.5. Without telling me the class in error, there is no way I can trouble shoot.
ReplyDeleteHi all!!!
ReplyDeleteIs it possible to have version X and version Y such that Y=X and still get this?:
Error compiling the report java source!
java.lang.UnsupportedClassVersionError: Bad version number in .class file at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:676)
... and so on....
Trying to compile a jasper report on iReport 3.7.1 (netbeans platform)...
Any guess?
Grazie mille!!
Sofia
Mac OSX v. 10.5.8 Intel
Java(TM) SE Runtime Environment (build 1.6.0_17-b04-248-9M3125)
sofiad:~ sofi$ javac -version
javac 1.6.0_17
// 27
ReplyDeleteHi Sofia,
This error message is only there when this version conflict occurs.
Even though you are using 1.6.0_17 jdk & jre; you may be using some other jar files that were generated with classes generated with a newer version of Java. So you can check Java versions used for them as well?
Thanks
ReplyDeleteHello,
ReplyDeleteRunning from the command line (Windows XP) I have,
Java as: java version "1.4.2_03"
Javac as: javac 1.6.0_11
This is causing a conflict. I can't find the older version of the JRE in the Windows Control Panel to remove it I can only see Java 6 Update 11 and the JDK SE Update 11. I can't find any reference to the older java on the Java console in the Windows Control Panel either.
When I'm using NetBeans, everything is working correctly as it is pointing to right folders.
My PATH is C:\Program Files\Java\jdk1.6.0_11\bin
How do I remove the older version?
Well this error is due to the compiler version and JRE version are different.
ReplyDeleteIf you are interested, You can easily reproduce it in Eclipse
Install jdk1.5 and Jdk1.6 in your system.
Create a simple java project in eclipse
Set the compiler version to 1.6 through menu->Windows-Preference->Compiler to 1.6
the select the project and change the buildpath jre to 1.5. (check eclipse help)
Try to run the program.
You get the this error!!!
Thanks for the solution.
ReplyDeleteThanks for solving my problem.
ReplyDeleteThanks... my eclipse was using a different version. Problem solved.
ReplyDeleteThanks Kamal this post helped me...
ReplyDeleteI was running an ANT build with javac version 1.6_0 update 21
....
...
< javac srcdir="src/main/test" destdir="target/classes" classpathref="compile.classpath" />
....
The classes were getting deployed to Apache Tomcat 6.0.26 container...I think Apache Tomcat still requires version 1.5...when I added my ant script above following two conditions it redeployed ...it worked for me. Here is the updated antscript line:
< javac srcdir="src/main/test" destdir="target/classes" classpathref="compile.classpath" source="1.5" target="1.5" />
a big thank you
ReplyDeletei have same problem i have jdk1.5 with mac osx and jvm 1.6 in eclipse n i cant found the sollll of this problem plz anybody suggest me but i have to do.........
ReplyDeleteWow, thank you, very nice and clear explanation. Refering to Eclipse (in my case) specifically, you have to go preferences->java->installed JREs an then check which you prefer.
ReplyDeletethis problem will be arised bcoz of jdk and jre are not the same version.
ReplyDeletehow to do 4x4 tiles with red n blue color using method start() it can changed into other color in JAVA lang?
ReplyDeleteI have deleted/reloaded Java 25 times. Get the same error: java.lang.ClassFormatError:Truncated class file???
ReplyDeleteCrisp and clear mate , i hav resolved the problem in short time thanks for the post.
ReplyDeleteThanks for article...solved the problem
ReplyDeleteHi,
ReplyDeleteI have a question that if I compile and build (war and ear files) with 1.6.0_22 and my weblogic server is running on 1.6.0_11, then will it work?
Both are using java 1.6 but server has 1.6 with updates 11 and in my system I have Java 1.6 with update 22.
Please put your suggestions.
Thanks in advance !!!!
-RP
Thanks very much...That was the best explanation i got on net.
ReplyDelete3 Cheers!....
:D
Combining class files into a JAR file to make standalone program?
ReplyDeleteI would like to have an exclusive Mother Board Troubleshooting Book with detailed depictions and steps?
ReplyDeleteI am having prolems loading some pages due to a java error. How can I fix the problem?
ReplyDeleteI am having prolems loading some pages due to a java error. How can I fix the problem?
ReplyDeleteHi admin, i noticed that it's hard to find this site in google, i found it on 23th spot, you should build some quality backlinks to www.digizol.com and after some time your traffic will increase dramatically when you reach google top10. I had the same problem with my site, your should search in google for - insane google ranking boost - it helped me a lot
ReplyDelete