java.lang.ClassFormatError: 不兼容的魔法值 218774561

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10327098/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 00:35:12  来源:igfitidea点击:

java.lang.ClassFormatError: Incompatible magic value 218774561

javaclassjarappletclassformaterror

提问by me me

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.

大家好,我今天正在为 Java 制作我的第一个小程序。我一直在服务器上使用子域,但我不知道该怎么做,因为我收到了这个非常奇怪的错误。

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

我在服务器中有我的 jar 和所有东西,但每次我尝试加载小程序时都会发生这种情况。

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

java.lang.ClassFormatError: 类文件 Evolution/EvolutionApplet 中不兼容的魔法值 218774561

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

经过研究,似乎不兼容的魔法值意味着 .jar 中的某些内容已损坏

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

这是网站http://dementedgames.site88.net/Main.html如果您需要网站上的 html 代码,jar 名称是 Evolution。

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

编辑:小程序应该从 Evolution.EvolutionApplet 启动,而不是 Evolution.Evolution

采纳答案by Andrew Thompson

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

原来的问题现在似乎已经解决了。我可以从http://dementedgames.site88.net/Evolution.jar下载 Jar

Update

更新

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

看来Evolution.Evolution类不是小程序!使用以下命令从命令行运行它:

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.

产生一个框架(具有非常“复古”的外观)!因此,忘记这个小程序废话,并使用Java Web Start从链接启动框架。

Old Answer

旧答案

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

OTOH 它现在抛出一个ClassNotFoundException(在检查 Jar 之后)让我认为它应该是:

<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 codeattribute worth noting.

code值得注意的属性有两个变化。

  1. The .classextension was removed. A minor matter, adding it is tolerated, but not correct.
  2. The Appletremoved from the class name.
  1. .class移除扩展。一个小问题,添加它是可以容忍的,但不正确。
  2. Applet从类名称中删除。

回答by BalusC

The magic valueof 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 218774561which in turn stands for the ASCII characters CR, LF, <and !(the CRLF is a newline). To see it yourself, run this piece of code:

有效 Java 类的魔法值为0xCAFEBABE,它是 的十六进制值3405691582。这由文件的前 4 个字节表示。但是你得到218774561的又代表 ASCII 字符CR, LF,<!(CRLF 是一个换行符)。要自己查看,请运行以下代码:

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.

这与网站提供的小程序相结合表明它是 a 的开始,<!DOCTYPE>而这又表明它是一个 HTML 文档。

So, the request to Evolution.jarhas apparently actuallyreturned 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.htmlin end of URL to /Evolution.jar). Then you'll see what the browser actuallyretrieved when it tried to download the applet. Perhaps it's a simple HTTP 404 error document.

因此,对 的请求Evolution.jar显然实际上返回了一个 HTML 文档。当您将浏览器地址栏中的当前请求 URI 更改为指向小程序的 URL(例如/page.html,将 URL 末尾更改为/Evolution.jar)时,您应该能够自己看到它。然后您将看到浏览器在尝试下载小程序时实际检索到的内容。也许这是一个简单的 HTTP 404 错误文档。

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

要修复它,只需确保archive属性中的 URL正确。它与您在浏览器地址栏中看到的当前请求 URL 相关。

回答by Kshitij

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

上面的 BalusC 已经很好地解释了它。除此之外,您可以检查此链接 线程:小程序中的不兼容的幻值 218774561 错误

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

似乎您的小程序标记的代码库和/或代码属性需要正确指向。