Forums > Java

Bad version number in .class file

June 27, 2011 | 1:30 pm

I have written a couple of Java classes on Max/MSP 5.1.8 on an iMac running Mac OS 10.6.7, as well as recompiling Userpath. They all work fine on my machine. However, when they are run on Macs using 10.5 or 10.4, we get error messages in the Max window as below:

java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at com.cycling74.max.MXJClassLoaderImpl.doLoadClass(MXJClassLoaderImpl.java:119)
at com.cycling74.max.MXJClassLoader.loadClazz(MXJClassLoader.java:88)
Could not load class ‘Userpath’

The ‘bad version number’ message seemed to suggest some kind of version issue with the JVMs, but I updated Java on one of the machines affected and the problem persisted.

I see that the MXJ compiler interface is calling the compiler in the 1.6.0.jdk (which is the only one installed on my Mac). I am not, however, using any Java 1.6 features (I’m probably not using anything that wasn’t already available one Java 1.0).

What incantation do I need to make sure that my .class files will run with older JVMs?


June 27, 2011 | 4:16 pm

I’m not sure what you mean by "MXJ compiler interface" since I never use it. If it’s an isolated class you’re trying to compile (which I’m guessing since there’s no package structure) then doing it from a console might work best:

javac -target [whatever] foo.java

[whatever] probably needs to be "1.5". Java 1.5 is standard on 10.5 Leopard (and PPC) and I think was rolled out somewhere in the 10.4 release line.

Eclipse setup is a little more involved, but not massively difficult.


June 27, 2011 | 4:17 pm

(Just checked on my G4 tower running 10.4.11: it’s Java 1.5.0_19.)


June 27, 2011 | 4:43 pm

With "MXJ compiler interface" I mean instantiating a [mxj myjavawhater] object, sending it a ‘viewsource’ message, and in the delightfully idiosyncratic editor window select Open Compile Window… from the Java menu.

IOW, use the development interface built into the mxj object. If you’re using Eclipse or a Terminal window you’ve probably forgotten that this even existed. But it’s a sort of convenient thing for quick Java edits without leaving Max/MSP.

In any case, I found the answer was to set the -target flag (and possibly a -source flag) in the Options field of the Compile Window dialog. Functionally identical to the command line options, we just have a ravishing UI to do it with.

I gather 1.5 should be sufficiently backwards-compatible for MacOS 10.4. Just to be sure I was compiling to -target 1.2, but that was probably overkill.


June 28, 2011 | 9:42 am

Two tie-up-loose-ends questions:

• Is targeting JVM 1.5 sufficiently backwards-compatible to cover our backs for Mac OS 10.4?

• In the [mxj quickie] Compile Window there a way to get the Options field to be sticky? ie., I’d like to have it always open up to -target 1.5 (or whatever) by default. The trouble with having to remember to always set the target is that you forget.


Viewing 5 posts - 1 through 5 (of 5 total)