java.lang.ClassFormatError: Incompatible magic value 218774561
Asked Answered
V

3

6

Hey everyone I am making my first applet for java today. I have been using a subdomain at a server and I don't know what to do because I am getting this really weird error.

I have my jar in the server and everything but every time I try to load the Applet this happens.

java.lang.ClassFormatError: Incompatible magic value 218774561 in class file Evolution/EvolutionApplet

Upon research it appears that an incompatible magic value means that something has been corrupted in the .jar

Here is the website http://dementedgames.site88.net/Main.html the jars name is Evolution if you need the html code it is at the website.

Edit: The applet should be launched from Evolution.EvolutionApplet not Evolution.Evolution

Vincenz answered 26/4, 2012 at 4:6 Comment(2)
How are you creating your jar?Eatmon
Great question. Shows research effort, and links to a failing example.Hoarsen
H
1

The original problem seems fixed now. I could download the Jar from http://dementedgames.site88.net/Evolution.jar

Update

It seems the Evolution.Evolution class is not an applet! Running it from the command line using:

java -jar Evolution.jar

Produces a frame (with a very 'retro' look)! As such, forget this applet nonsense, and launch the frame from a link using Java Web Start.

Old Answer

OTOH it now throws a ClassNotFoundException that (after inspecting the Jar) makes me think it should be:

<html>
<head>
<title>Evolution</title>
</head>
<body bgcolor="#000000" text="#906060">
<center>
<applet code="Evolution.Evolution" archive="Evolution.jar" width="800" height="600">
</applet>
</center>
</body>
</html>

There are two changes to the code attribute worth noting.

  1. The .class extension was removed. A minor matter, adding it is tolerated, but not correct.
  2. The Applet removed from the class name.
Hoarsen answered 26/4, 2012 at 5:55 Comment(0)
P
14

The magic value of a valid Java class is 0xCAFEBABE, which is the hex value of 3405691582. This is represented by the first 4 bytes of the file. But you're getting 218774561 which in turn stands for the ASCII characters CR, LF, < and ! (the CRLF is a newline). To see it yourself, run this piece of code:

int magic = 218774561;
ByteBuffer b = ByteBuffer.allocate(4);
b.putInt(magic);
System.out.println(new String(b.array()));

This in combination with the applet being served by a website suggests that it's the start of a <!DOCTYPE> which in turn suggests that it's a HTML document.

So, the request to Evolution.jar has apparently actually returned a HTML document. You should be able to see it yourself when you change the current request URI in browser address bar to point to applet's URL (e.g. change /page.html in end of URL to /Evolution.jar). Then you'll see what the browser actually retrieved when it tried to download the applet. Perhaps it's a simple HTTP 404 error document.

To fix it, just make sure that the URL in the archive attribute is correct. It's relative to the current request URL as you see in browser address bar.

Pentlandite answered 26/4, 2012 at 4:22 Comment(0)
H
1

The original problem seems fixed now. I could download the Jar from http://dementedgames.site88.net/Evolution.jar

Update

It seems the Evolution.Evolution class is not an applet! Running it from the command line using:

java -jar Evolution.jar

Produces a frame (with a very 'retro' look)! As such, forget this applet nonsense, and launch the frame from a link using Java Web Start.

Old Answer

OTOH it now throws a ClassNotFoundException that (after inspecting the Jar) makes me think it should be:

<html>
<head>
<title>Evolution</title>
</head>
<body bgcolor="#000000" text="#906060">
<center>
<applet code="Evolution.Evolution" archive="Evolution.jar" width="800" height="600">
</applet>
</center>
</body>
</html>

There are two changes to the code attribute worth noting.

  1. The .class extension was removed. A minor matter, adding it is tolerated, but not correct.
  2. The Applet removed from the class name.
Hoarsen answered 26/4, 2012 at 5:55 Comment(0)
K
0

BalusC above has explained it really well. In addition to that you can check this link Thread: Incompatible magic value 218774561 error in applet

It seems that the codebase and/or the code attribute of ur applet tag need to pointed properly.

Karyotin answered 26/4, 2012 at 4:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.