1

I'm trying to code an applet and put it in my website. I remember doing this a long time ago using Borland back when 1.4 was the latest version. It of course used the applet tag (which I'm using currently) and it had no issues. But anyways, I put the class files in httpdocs/ under its own directory, and then used this code in the web page:

<applet code="wsavatar/WSAvatar" width="425" height="150> Your browser does not support the applet tag. </applet>

And when I try to load the page, this happens:

Java Plug-in 1.6.0_17 Using JRE version 1.6.0_17-b04 Java HotSpot(TM) Client VM

java.lang.ClassFormatError: Incompatible magic value 1008813135 in class file   
  wsavatar/WSAvatar
  at java.lang.ClassLoader.defineClass1(Native Method)
  at java.lang.ClassLoader.defineClass(Unknown Source)
  at java.security.SecureClassLoader.defineClass(Unknown Source)
  at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
  at java.lang.ClassLoader.loadClass(Unknown Source)
  at java.lang.ClassLoader.loadClass(Unknown Source)
  at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
  at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
  at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
  at java.lang.Thread.run(Unknown Source)
Exception: java.lang.ClassFormatError: Incompatible magic value 1008813135
in class file wsavatar/WSAvatar

I have tried making a quick local html file to load the applet using the same applet code and it worked. I have looked around online and have heard various things pertaining to this error, but nothing seems to alleviate it, that I've found. Any ideas?

Ben

Kredns
  • 36,461
  • 52
  • 152
  • 203
Ben
  • 11
  • 3

2 Answers2

5

The magic number is a four byte value (0xCAFEBABE) at the start of the class file that marks it as a class file rather than any other kind of data.

So what type of file has magic number 1008813135? In hex that becomes that bytes 0x3C, 0x21, 0x44, 0x4F. Interpreted as character data in common Latin encodings is "<!DO. Probably continuing as "<!DOCTYPE". What we have here is an HTML file. This is probably an error page returned by a broken server only with a non-error success code in the HTTP response.

Have a look at what is actually being served. A web browser will probably show the page. It is worth learning to use telnet (or nc) and type in the HTTP response by hand. There are also various utilities for inspecting HTTP traffic.

Tom Hawtin - tackline
  • 145,806
  • 30
  • 211
  • 305
  • Thanks, it appears, as I mentioned in response to the other answer, that it's a 404 page that it's returning, hence the tag. – Ben Dec 09 '09 at 15:59
3

The problem appears to be in your website, not your code. Googling around, the error seems to be most frequently reported with systems such as OpenCMS (especially for URLs that are on port 8080).

So, what I imagine is happening is that the browser's call to load the applet is actually failing, but is returning data rather than a 404/500 error. The Java VM is attempting to interpret the returned error page as if it was a class file, and quite correctly complaining that it doesn't seem to be a valid class file after all. (This happens quite often with content management systems that redirect to the home page rather than return an actual HTTP error to the user.)

To test, try manually typing the URL to the applet (not the page it is hosted in, the applet itself) in your browser and see what the server returns.

  • Ah, yes, it is failing to load the applet. We aren't using a prewritten CMS, though it is using Savant3, and the direct URL to the avatar is returning a 404. – Ben Dec 09 '09 at 15:58
  • Uh, excuse me, I mean a direct URL to the applet. – Ben Dec 09 '09 at 17:43
  • I was able to add an entry for the applet itself as if it was a separate page, and it resolved this error (though now I have more to debug!). Thank you. – Ben Dec 10 '09 at 06:16