Version issue? Or what else can it be?
Hi All,
I'm new to Java and am still confused by many things.
Let me first state the problem that I want to solve: I have an application that is made to work as a bunch of web pages generated locally according to user's input and using Javascript. The missing element is access to SQL (MS SQL Server 7.0, in my case). After a lot of browsing, I concluded that, with Firefox as browser, my only way to access the DB locally (without a running web server) would be through a Java applet.
I got inspiration from the web, created an applet, installed the latest JDK, and failed to run. The error message looks like this:
Java Plug-in 1.6.0_26
Using JRE version 1.6.0_26-b03 Java HotSpot(TM) Client VM
User home directory = C:\Users\Timisoara
----------------------------------------------------
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
o: trigger logging
q: hide console
r: reload policy configuration
s: dump system and deployment properties
t: dump thread list
v: dump thread stack
x: clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------
java.lang.UnsupportedClassVersionError: HelloWorld : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknow n Source)
at sun.plugin2.applet.Applet2ClassLoader.findClass(Un known Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(U nknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Un known Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Un known Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unk nown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unk nown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.lang.UnsupportedClassVersionError: HelloWorld : Unsupported major.minor version 51.0
I kept searching the web, concluded that I'm trying to see a 1.7 binary code with a 1.6 able browser, and looked for alternatives.
In my search, I stumbled over this "Hello World" applet. And now comes the puzzling part: if I try to run the example from their web site, it works. If I download the .class and .html files provided, and run them locally (same browser), I end up with the same error message.
What's the explanation? How can I go over this error?
Thanks,
SxN
Re: Version issue? Or what else can it be?
20 views, not one suggestion... is it so weird? Is there, perhaps, a work around?
(biting nails)
Thanks,
SxN
Re: Version issue? Or what else can it be?
The class version exception indicates the code was compiled with a JDK that is later than the JRE running said code. The target versions can be set when compiling, to allow earlier versions of the JRE to run the code (assuming the code is compatible with those versions). The browser showing different results online vs. locally suggests perhaps 2 jre versions, each run in the different environment, but I won't speculate as to why.
Re: Version issue? Or what else can it be?
Thanks for you reply.
I suspected that is a version issue. I tried compiling with -target 1.6, and the compilation failed with:
javac: target release 1.6 conflicts with default source release 1.7. I got the same error with target 1.5.
The next step was to install all JRE and JDK versions available, which made JRE unavailable for FireFox too. After that, I reinstalled the JDK (which will install the JRE as well). When I attempted to use my test class, FireFox asked to update its plugin, and afterward failed in the same way.
I tried to use online compilers and I forced version 1.6, then 1.5 - nothing helped.
I tried the simple example "Hello world" mentioned in my first post, and, as I mentioned, the online execution works, the local one fails.
What are my options?
Thanks,
SxN
Re: Version issue? Or what else can it be?
Hello again,
I (kind of) solved my problem. Found an old W2K box, with an old Java compiler (1.4.2_80), and used that. It compiles and runs on the old machine, it runs on the new one too.
Well, time to move on.
Regards,
SxN
Re: Version issue? Or what else can it be?
If you download an earlier version of the JDK (The same as your JRE) you won't need to use a workaround, have a look at: Java SE JDK 6u25 Download