The Artima Developer Community
Sponsored Link

Java Answers Forum
java.lang.ClassFormatError: Bad major verision number

8 replies on 1 page. Most recent reply: Mar 18, 2002 7:02 AM by Lynn Hollerman

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 8 replies on 1 page
Lynn Hollerman

Posts: 67
Nickname: gmholler
Registered: Mar, 2002

java.lang.ClassFormatError: Bad major verision number Posted: Mar 15, 2002 9:37 AM
Reply to this message Reply
Advertisement
I am a Java newbie. I am using Netscape 4.79 under Sun OS 5.8, trying to learn the language. I have been looking at various tutorials on the Web and trying their sample programs; to compile the programs from the tutorials, SDK 1.4 was installed on the system. However, the subject is an error I get when I try to test the applet code that I've copied from a tutorial - the code works fine in the appletviewer, and it appears to work when I use IE on a PC. I can find no reference to this error, past the Sun site's telling me that this is an exception. I want to know what it means and what I should do. I know the code works, it's from Sun and operates fine on their site - I just wanted to go thru all the steps in putting an applet on the Web - why can't I get it to work for me?

Thanks!


Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: java.lang.ClassFormatError: Bad major verision number Posted: Mar 15, 2002 9:56 AM
Reply to this message Reply
You say "the code works fine in the appletviewer, and it appears to work when I use IE on a PC" -- when does it not work?

Lynn Hollerman

Posts: 67
Nickname: gmholler
Registered: Mar, 2002

Re: java.lang.ClassFormatError: Bad major verision number Posted: Mar 15, 2002 10:46 AM
Reply to this message Reply
When does it NOT work? On a Solaris machine running Sun OS 5.8, under Netscape 4.79. The applet was compiled under v1.4 of the Java SDK.

Or maybe I'm just misunderstanding - I did it in one of the tutorials with the appletviewer, so I thought you were supposed to be able to compile some code, write some HTML with a <applet> tag that referred to the code, and look at it in a browser. No?

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: java.lang.ClassFormatError: Bad major verision number Posted: Mar 15, 2002 12:01 PM
Reply to this message Reply
Hmm... It might be that Netscrape 4.7 is a bit old and Java 1.4 was just released. Maybe if you compile with the 1.3 JDK, it will solve the problem. Either that, or get the latest version of Netscape. It might also be possible to update the plugin on the Netscape you have.

Lynn Hollerman

Posts: 67
Nickname: gmholler
Registered: Mar, 2002

Re: java.lang.ClassFormatError: Bad major verision number Posted: Mar 15, 2002 12:21 PM
Reply to this message Reply
Wait...a lot of this just doesn't make sense...

They just upgraded to 4.79 at my request - they said that was the latest and greatest version of Netscape for Solaris - doesn't Sun make both Java AND Solaris? Shouldn't their THEIR language work best on THEIR OS?

I don't know of any way to run under a different SDK *just* on my workstation - it's not like I have the permissions to create a bunch of different directories on this system, unless they're in my own home directory!

About plug-ins...I checked on those this morning, and there AREN'T any loaded on the system - but applets from other servers run just fine. I was told that they weren't necessary any more for Solaris...no?

I may try to talk the sysadmins into downloading and installing a plug-in for me - can't hurt!

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: java.lang.ClassFormatError: Bad major verision number Posted: Mar 15, 2002 12:52 PM
Reply to this message Reply
The question is what JVM the browser is running. Sun doesn't make the browser. Just because you install a particular version of Java, doesn't mean the browser is using that JVM. I am not sure how things work on Solaris, but I think Netscape installs a version of the JVM that it uses, regardless of what you already or subsequently have installed (I don't know if you can configure it to use another, maybe you can). I was surmising that the browser's version of the JVM is the one that is rejecting the Java 1.4-compiled code, because it is newer than the JVM.

Also, I didn't say run under a different SDK, just compile the java files with a different version of the SDK and see if it then runs in your current browser configuration.


Additionally are you using the new plugin-style HTML? If you want to try it, search for the "HTML converter" tool from Sun that will convert the HTML to the plugin style. Look at the text in your HTML file, maybe the version it is specifying is not 1.4; look for something like "<PARAM NAME="type" VALUE="application/x-java-applet;version=1.3">" and "<EMBED type="application/x-java-applet;version=1.3" ..."

Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Re: java.lang.ClassFormatError: Bad major verision number Posted: Mar 15, 2002 5:50 PM
Reply to this message Reply
I think Matt is on the right track.

The Java class file has major and minor version numbers right after the first four byte magic number (0xCAFEBABE). Here's the history, as I understand it:

* Version 1.0 JVMs were required to support 45.0 (major number 45, minor number 0) through 45.3.
* Version 1.1 JVMs support 45.0 through 45.65535.
* Version1.2 JVMs support 45.0 through 46.0.
* Version 1.3 JVMs support 45.0 through 47.0
* Version 1.4 JVMs support 45.0 through 48.0

By default, the javac compiler for 1.4 generates class files with a major version of 48. Those class files won't run on any JVMs prior to 1.4.

You don't need to download a previous SDK, however, to get class files with lower version numbers. You can just use the -target flag of javac. For example, the following will force the 1.4 compiler to generate class files compatible with 1.2 JVMs:

javac -target 1.2 *.java

More details about javac are at:

http://java.sun.com/j2se/1.4/docs/tooldocs/solaris/javac.html

Even though you have the latest Netscape browser for Solaris, that browser's JVM is not 1.4. That's why it can't use the class files that come out of 1.4 javac by default.

The reason there's a Java Plug-In JVM that you have to install yourself, in addition to a JVM that comes with the browser has mostly to do with the licensing difficulties between Microsoft and Sun. At least that's what it is in the case of Internet Explorer.

I'm not sure what's going on with Netscape, though I suspect it has something to do with irrelevance. Not a single flavor of Netscape browser appears in the top 50 browsers used by people to use this web site. That makes you a rare exception yourself, if you are using Netscape to look at this site.

David de Lorenzo

Posts: 2
Nickname: delo
Registered: Mar, 2002

Possible reason Posted: Mar 17, 2002 4:51 AM
Reply to this message Reply
I think that you have to compile again in the example applet in your installed java compiler. If you use SDK1.4 and the example applet was compiled in another newer compiler, you could have a "
java.lang.ClassFormatError: Bad major version number".

Bye!

Lynn Hollerman

Posts: 67
Nickname: gmholler
Registered: Mar, 2002

Re: java.lang.ClassFormatError: Bad major verision number Posted: Mar 18, 2002 7:02 AM
Reply to this message Reply
Before anything, I want to thank all of you that have replied! Thank you all so VERY much! You have all given prompt and useful answers to my questions - I am SO grateful!!

I use this Solaris system at work - right now, it's all I have, and I'm pretty much at the mercy of what the sysadmins allow installed. At home, I have a PC running Windows 98 - on that, I have Netscape (4.78), IE (6.0), and Opera (6.01) - and I tried my applet(still compiled under 1.4) in each - and found out something interesting: Netscape wouldn't run the applet and gave me the same error I was getting on the Solaris system - UNTIL I enabled the Java plug-in - then the applet ran flawlessly. Why? How is it that other applets run fine without that plug-in enabled?

Something else I noticed - NO applets, ANYWHERE, would run under IE - this is a purely default version, I haven't done much of anything to customize it, as at home I usually use Netscape; so what do I need to do to enable applets in IE? (Just for consistency, and if you're interested, Opera had no trouble running the applet - this is Opera "straight out of the box", no customizations.)

Thanks to your answers, now I know just what "major version number" is being talked about! I tried re-compiling with the "-target 1.2" as Bill suggested - and got a different error under Solaris - now it's "class xxxx could not be loaded" - hopefully, I can figure that one out!

Speaking of converting HTML, I read a book that talked about having to convert applets in HTML before running them - is that for all applets, or just some? When I first heard about applets, about 6 years ago, a book I had then said all you needed to do was compile your applet, put an <APPLET> tag in your HTML and refer to the applet's .class file in the parameters of that statement and the applet would execute in a Java-enabled browser. Is that no longer true?

Flat View: This topic has 8 replies on 1 page
Topic: Object and Image Classes Previous Topic   Next Topic Topic: URGENT!!!     .......Opening a web site from JEditorPane

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use