Java.lang.ClassFormatError: Incompatible magic value 218774561

Hi everyone, I am making my first java applet today. I use the subdomain on the server, and I do not know what to do, because I get this really strange error.

I have my bank on the server and that’s all, but every time I try to download the Applet, this happens.

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

As a result of the study, it seems that an incompatible magical meaning means that something was damaged in the .jar

Here is the website http://dementedgames.site88.net/Main.html the name of the cans is Evolution if you need the html code on the website.

Edit: applet must be launched from Evolution.EvolutionApplet not Evolution.Evolution

+6
source share
3 answers

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

Update

The Evolution.Evolution class does not seem to be an applet! By running it from the command line using:

 java -jar Evolution.jar 

Creates a frame (with a very "retro")! So, forget about this paragraph of the applet and start the frame from the link using Java Web Start .

Old answer

OTOH now throws a ClassNotFoundException , which (after checking 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.

  • The .class extension has been removed. A small thing, adding it, is tolerant, but not right.
  • Applet removed from class name.
+1
source

The magic value of a valid Java class is 0xCAFEBABE , which is the hexadecimal value of 3405691582 . This is represented by four bytes of a file. But you get 218774561 , which in turn means ASCII characters CR , LF , < and ! (CRLF is a new line). To verify this, run this piece of code:

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

This, combined with the applet served by the website, suggests that this is the beginning of <!DOCTYPE> , which in turn assumes that it is an HTML document.

So, the Evolution.jar request appears to have actually returned the HTML document. You should see this yourself when you change the URI of the current request in the address bar of the browser to indicate the URL of the applet (for example, change /page.html at the end of the URL to /Evolution.jar ). Then you will see what the browser really received when it tried to download the applet. Perhaps this is a simple HTTP 404 protocol.

To fix this, just make sure the URL in the archive attribute is correct. This is relative to the current request URL, as you see in the address bar of the browser.

+14
source

BalusC above explained this very well. In addition to this, you can check this link Subject: Incompatible magic value 218774561 applet error

It seems that the code-code and / or url code attribute of the applet tag should be correctly specified.

0
source

Source: https://habr.com/ru/post/914187/


All Articles