Ok, what the heck causes these stupid exceptions. I can't find hardly any documentation on it. I've tried running my mortgage calculator on a different computer and it won't show up because a unsupportedflavorexception. I know it's something about the major or minor version, but what do you do about it? How can you solve something like this?

Recommended Answers

All 11 Replies

It's an AWT exception thrown by datatransfer operations if the datatype isn't supported.
Things like drag and drop, clipboard operations, etc.

I guess the error occurs on different vendor implementations of the JVM? Possibly on macs or unix?

DataFlavors are static descriptors for data types. You get this exception if the DataFlavor you want doesn't exist on the platform you're running on.
Or according to my Swing reference (which is almost as cryptic):
"an unusual aspect of drag-and-drop in the Java environment is flavor maps. A flavor map is a mapping between a device-dependent data type and the Java device independent data type. This allows the Java applicatio to transfer data with a native application without requiring the Java application to know the specifics about the native data types."

It MUST be the JVM version. I've written code before that will run on any machine(as it should), but now that I'm compiling in 1.5, nothing works on other peoples computers. What should I do? Should I compile i 1.4?

It is the JVM I am pretty sure. I just tried it on my Mac, running Tiger, and it does not work. If I run your applet using Firefox on Windows XP, runs just fine.

This has me puzzled. Shouldn't 1.5 be backwards compatible?

I am actually getting a different exception when I try it on the Mac using Safari (which is the standard browser on the Mac).

java.lang.UnsupportedClassVersionError: MortgageApplet (Unsupported major.minor version 49.0)
	at java.lang.ClassLoader.defineClass0(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
	at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:157)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
	at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:123)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
	at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:561)
	at sun.applet.AppletPanel.createApplet(AppletPanel.java:631)
	at sun.plugin.AppletViewer.createApplet(AppletViewer.java:1953)
	at sun.applet.AppletPanel.runLoader(AppletPanel.java:560)
	at sun.applet.AppletPanel.run(AppletPanel.java:298)
	at java.lang.Thread.run(Thread.java:552)

This is also kind of helpful. If you hit this site it tells you what version of Java your browser is running.

http://www.javatester.org/version.html

On the Mac where I can't run it, its saying:

Java Version: 1.4.2_07 from Apple Computer

On my PC, where it works just fine, I get:

Java Version: 1.5.0_01 from Sun Microsystems, Inc.

I am guessing its a 1.5 thing. Are you using a 1.5 specific class? Can it compile in 1.4?

It's not the JVM version, it's the JVM implementation details.
If Apple failed to provide a mapping of some core datatypes to their internal format in their JVM (I don't think the JVMS obliges the implementation of any such mappings) you get an exception.

The UnsupportedClassVersionError is thrown when you try to run a class on an older JVM than the one it was compiled for.
In this case the class was compiled for 1.5 and Safari apparently has a 1.4 JVM.
If you're running MacOS 10.3 or earlier you will not have a 1.5 compliant JVM as Apple doesn't supply one for any OS except 10.4 (or whatever the latest is).

I compiled it in 1.5. I guess the only way to fix it, is compile in 1.4. I still don't get why it's not backward compatible though.

It is backwards compatible, that's not the problem.
The problem is that 1.4 isn't forwards compatible (it can't read a fileformat that didn't exist when it was created, not that weird actually).

Try to compile with the "-target 1.4 -source 1.4" options and see what happens.
If you've not used any 1.5 specific language features it should compile and yield a version 48 classfile which can be read and executed by a 1.4 as well as a 1.5 JVM.

I think that's going to work!!! But now I have a bunch of errors with the array list. It's saying it's expecting an object, not in int...That doesn't make sense to me because an int is an object, but I'll go back and change a bunch of my code. If it works, I'll let you know.

An int is not an Object.
In 1.5 a new feature called autoboxing/unboxing was introduced that allows you to treat primitives like their wrapper objects in many conditions with the compiler handling the conversion between the primitives and the wrappers for you.

In 1.4 (and before) you had to do that yourself, which often was a more than a bit tedious task.
So you're going to have to do a lot of

myList.add(new Integer(i));
// ...
int i = ((Integer)myList.get(idx)).intValue();

where in 1.5 you can often do

myList.add(i);
// ..
int i = myList.get(idx);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.