java.lang.ClassFormatError: Extra bytes at end of class file

前端 未结 6 1606
鱼传尺愫
鱼传尺愫 2021-01-04 11:23

I\'m getting an odd error when I try and run this program. The class compiles fine into multiple .class files and I compiled it last week (before editing it) just fine. But

6条回答
  •  旧时难觅i
    2021-01-04 11:53

    This is indeed disallowed as per VM Spec 4.9.1:

    The class file must not be truncated or have extra bytes at the end.

    This can occur if there's an incompatibility in Java compiler and Java runtime used. Verify both versions and make sure that you compile for the right runtime versions. I.e. the compiled class can be used with same or newer runtime version, but not always with older runtime versions. Check the versions using java -version and javac -version.

    Another common cause is that the file get corrupted during file transfer (FTP) between different machines. This transfer should be done in binary mode rather than text mode.

    Another possible cause is a hardware error, e.g. corrupt harddisk/file/memory. Try recompiling or another machine.

提交回复
热议问题