Problem with version of Java. . .

Hey -

I wrote a java applet which works on my computer, and on some other computers. But, some people (even though they have java) get only a red X and it refuses to load.

Why does this happen? And, what can be done to avoid this problem?

This is the sample error message from the java console:

java.lang.UnsupportedClassVersionError: Bad version number in .class file

at java.lang.ClassLoader.defineClass1(Native Method)

at java.lang.ClassLoader.defineClass(Unknown Source)

at java.security.SecureClassLoader.defineClass(Unknown Source)

at java.net.URLClassLoader.defineClass(Unknown Source)

at java.net.URLClassLoader.access$100(Unknown Source)

at java.net.URLClassLoader$1.run(Unknown Source)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(Unknown Source)

at sun.applet.AppletClassLoader.findClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at sun.applet.AppletClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at sun.applet.AppletClassLoader.loadCode(Unknown Source)

at sun.applet.AppletPanel.createApplet(Unknown Source)

at sun.plugin.AppletViewer.createApplet(Unknown Source)

at sun.applet.AppletPanel.runLoader(Unknown Source)

at sun.applet.AppletPanel.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

many thanks in advance,

Dave

[1515 byte] By [Dave_Carta] at [2007-11-27 11:37:37]
# 1

what version of Java are you currently using? and what versions of Java are the

users of your system running? :)

lem@phila at 2007-7-29 17:15:31 > top of Java-index,Java Essentials,New To Java...
# 2

> Why does this happen?

The browser's JVM is a version which is incompatible with the version of Java for which the applet is compiled.

And, what can be done to avoid this problem?

Compile for an earlier version of Java, or ask the user to upgrade their JVM.

~

yawmarka at 2007-7-29 17:15:32 > top of Java-index,Java Essentials,New To Java...
# 3

You probably compiled your code with a newer version

of Java then they are using to run.

Most people have 1.4.2 (id guess).

So try recompiling your Java 5 or 6 code with the

-source 1.4 -target 1.4 flags.

Or better yet, tell them to upgrade! : )

TuringPesta at 2007-7-29 17:15:32 > top of Java-index,Java Essentials,New To Java...
# 4

okay -- will do.

Incidentally, will simply using that compiler flag do it? Or will I have to change my code?

Also, where do people upgrade their Java?

Dave_Carta at 2007-7-29 17:15:32 > top of Java-index,Java Essentials,New To Java...
# 5

Yeah, using NetBeans, I get the following error:

init:

deps-jar:

Compiling 1 source file to C:\java\source\RPS\build\classes

javac: source release 1.6 requires target release 1.6

BUILD FAILED (total time: 0 seconds)

Is this a problem because I'm using Swing? If I can't change it to 1.4, is there a way the program can automatically bring users to an upgrade page?

Thanks,

Dave

Dave_Carta at 2007-7-29 17:15:32 > top of Java-index,Java Essentials,New To Java...
# 6

check the message, it is quite clear.

Based on what you learn from the message, change your compiler settings.

jwentinga at 2007-7-29 17:15:32 > top of Java-index,Java Essentials,New To Java...