【问题标题】:Magic value error when I run my applet运行小程序时出现魔术值错误
【发布时间】:2012-09-17 10:07:17
【问题描述】:

我创建一个 Applet 并使用以下代码生成 jar 文件

JAR 文件

"c:\arquivos de programas\java\jdk1.7.0_05\bin\jar" cvf C:\Users\lucas\Desktop\AbrirAplicativo3000.jar C:\Users\lucas\workspace\WebcamApplet\bin\com\colorfulwolf\webcamapplet\WebcamApplet.class C:\Users\lucas\workspace\WebcamApplet\bin\com\colorfulwolf\webcamapplet\QRCodeProcessor.class C:\Users\lucas\workspace\WebcamApplet\bin\com\colorfulwolf\webcamapplet\QRCodeListener.class C:\Users\lucas\workspace\WebcamApplet\bin\com\colorfulwolf\webcamapplet\OpenCVWebCam.class C:\Users\lucas\workspace\WebcamApplet\bin\com\colorfulwolf\webcamapplet\CVImageProcessor.class C:\Users\lucas\workspace\WebcamApplet\bin\com\colorfulwolf\webcamapplet\AbstractProcessor.class C:\Users\lucas\workspace\WebcamApplet\bin\com\colorfulwolf\webcamapplet\gui\ImagePanel.class C:\Users\lucas\workspace\WebcamApplet\bin\com\colorfulwolf\webcamapplet\gui\LabelPanel.class C:\Users\lucas\workspace\WebcamApplet\bin\com\colorfulwolf\webcamapplet\gui\LoadingScreen.class C:\Users\lucas\workspace\WebcamApplet\bin\com\google\zxing\StringsResourceTranslator.class C:\Users\lucas\workspace\WebcamApplet\bin\com\google\zxing\client\j2se\BufferedImageLuminanceSource.class C:\Users\lucas\workspace\WebcamApplet\bin\com\google\zxing\client\j2se\CommandLineRunner.class C:\Users\lucas\workspace\WebcamApplet\bin\com\google\zxing\client\j2se\GUIRunner.class C:\Users\lucas\workspace\WebcamApplet\bin\com\google\zxing\client\j2se\ImageConverter.class C:\Users\lucas\workspace\WebcamApplet\bin\com\google\zxing\client\j2se\MatrixToImageWriter.class

我正常地唱了 JAR 文件。

我将 JAR 文件放在可见的 HTTP (http://www.netimoveis.com/AbrirAplicativo3000.jar) 中

在我的ASPX 页面中,我按照此代码调用APPLET

<applet code="com.colorfulwolf.webcamapplet.WebcamApplet" 
    archive="http://www.netimoveis.com/AbrirAplicativo3000.jar, http://www.netimoveis.com/AbrirAplicativoAssinado3000.jar"
    height="550" width="550">
</applet>

但是当我尝试运行时,我得到了错误

Incompatible magic value 218774561 error in applet

有人可以帮助我吗?

【问题讨论】:

  • 小程序所在页面的网址是什么?
  • 两个 jar 文件应使用相同的证书进行签名。确保是这种情况
  • 嗯,我正在开发这个,所以,在localhost中,而我的jar文件在可见的HTTP中,并且localhost可以看到。
  • @OmarJackman 都使用相同的证书签名。

标签: java


【解决方案1】:

您的AbrirAplicativo3000.jar 未正确打包。如果你看里面,它有这样的结构:

META-INF/
C:/
  Users/
    lucas/
      workspace/
        WebcamApplet/
           bin/
             com/ --> this is where the jar should start from.
               ...

尝试在jar 命令上使用-C 选项,如下所示:

"c:\arquivos de programas\java\jdk1.7.0_05\bin\jar" cvf C:\Users\lucas\Desktop\AbrirAplicativo3000.jar -C C:\Users\lucas\workspace\WebcamApplet\bin\ .

this magic number 也不是第一次出现在 SO 上,尽管它似乎与错误的 URL 更相关。但是,我确实使用您提供的 URL 下载了 jar,因此请尝试重新打包它。

【讨论】:

  • 我的 jar 文件必须从 com/ 目录开始,而不是 C:/Users/lucas.... 路径?
  • 是的,第一级应该包括您的META-INFcom 文件夹
  • 我正在尝试通过 Eclipse IDE 中的导出工具生成 jar,但是当我尝试设置我的 Manifest 时,我的包含我的主要类的包没有出现
  • 我想你的意思是JAR File Exporter。确保您的主类有一个带有public static void main(String args[]) 签名的方法。但是请解释为什么您需要在小程序中包含main(args[])。如果它只是要在浏览器/容器中运行,则不需要它。
  • 奇怪,我通过 JAR File Exporter 生成了一个新的 JAR,但是小程序在执行时仍然出错。小程序中不兼容的魔法值218774561错误
【解决方案2】:

魔术值错误意味着类文件没有按应有的整数 0xCAFEBABE 开头。您可能遇到了传输或压缩问题。

如果您可以在十六进制编辑器中打开文件,则可以查找这些字节。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多