一分钟前工作的方法上的 java.lang.VerifyError

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3019394/
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-29 23:58:35  来源:igfitidea点击:

java.lang.VerifyError on method that worked a minute ago

javaverifyerror

提问by Travis

Apologies in advance but I have never seen this error before and don't know what to include. I am using NetBeans and suddenly began getting this error:

提前道歉,但我以前从未见过这个错误,也不知道该包括什么。我正在使用 NetBeans 并突然开始收到此错误:

Exception in thread "AWT-EventQueue-0" java.lang.VerifyError: (class: market/CostOperations, method: <init> signature: ()V) Constructor must call super() or this()
            at Bluebuild.Main.refreshTables(Main.java:748)
            at Bluebuild.Main.formComponentShown(Main.java:649)
            at Bluebuild.Main.access0(Main.java:28)
            at Bluebuild.Main.componentShown(Main.java:374)
            at java.awt.Component.processComponentEvent(Component.java:6095)
            at java.awt.Component.processEvent(Component.java:6043)
            at java.awt.Container.processEvent(Container.java:2041)
            at java.awt.Window.processEvent(Window.java:1836)
            at java.awt.Component.dispatchEventImpl(Component.java:4630)
            at java.awt.Container.dispatchEventImpl(Container.java:2099)
            at java.awt.Window.dispatchEventImpl(Window.java:2478)
            at java.awt.Component.dispatchEvent(Component.java:4460)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

I have not a clue what happened. I didn't even modify market/CostOperations.

我不知道发生了什么。我什至没有修改市场/成本运营。

Here's the constructor though:

这是构造函数:

public CostOperations() throws ParserConfigurationException, SAXException, IOException {

        //Open the xml file
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        f = new File(dbName);
        doc = builder.parse(f);
        System.out.println(f.canWrite());

        //Create the XPath
        XPathFactory xpfactory = XPathFactory.newInstance();
        path = xpfactory.newXPath();

    }

In Debug Mode I get this:

在调试模式下,我得到这个:

debug:
Have no FileObject for C:\Program Files (x86)\Java\jdk1.6.0_20\jre\lib\sunrsasign.jar
Have no FileObject for C:\Program Files (x86)\Java\jdk1.6.0_20\jre\classes

I just need to know what is causing the error and how to fix it. Thanks!

我只需要知道是什么导致了错误以及如何修复它。谢谢!

回答by Michael Mrozek

A VerifyErrormeans the bytecode is invalid, which points to a compiler problem. I would try rebuilding everything in the hopes that it goes away, but otherwise you should file a bug. The bytecode is required to call the superclass constructor manually via invokenonvirtual superclass/<init>()V, but you shouldn't need to add super();in the source, the compiler should handle that

AVerifyError表示字节码无效,说明编译器有问题。我会尝试重建一切,希望它消失,否则你应该提交一个错误。字节码需要通过 手动调用超类构造函数invokenonvirtual superclass/<init>()V,但您不需要super();在源代码中添加,编译器应该处理

回答by Stephen C

I would seriously doubt that this is a Java compiler bug. Something like that would most likely have been noticed by someone else and reported as a bug. But you can verify this by recompiling the file and using javapto disassemble the bytecodes. Look for the the following instruction in the constructor code:

我会严重怀疑这是一个 Java 编译器错误。类似的事情很可能会被其他人注意到并报告为错误。但是您可以通过重新编译文件并使用javap反汇编字节码来验证这一点。在构造函数代码中查找以下指令:

    invokespecial #1 <Method java.lang.Object()>

I think it is more likely that something is modifying the bytecodes afterthe compiler has written them. Possibilities include some profiler that is modifying the bytecodes to inject profiling hooks, or some annotation processor that is injecting dependencies, cut points, etc.

我认为更有可能是在编译器编写字节码之后修改了字节码。可能的情况包括一些分析器正在修改字节码以注入分析钩子,或者一些注解处理器正在注入依赖项、切点等。

回答by xelamitchell

It is definitely a compiler issue: the bytecode generated has a different Binary Format.

这绝对是一个编译器问题:生成的字节码具有不同的二进制格式。

To solve this: Right click on the project -> Properties -> Sources -> Source/Binary Format

要解决此问题:右键单击项目 -> 属性 -> 源 -> 源/二进制格式

Change it to whatever format is suitable to your code.

将其更改为适合您的代码的任何格式。

回答by StarCrafter

This happened to me in Netbeans. In netbeans, when you try to copy a .java file in same directory without "refactor copy", it places the new file as "YourJavaFile_1.java" and problem occures. But if you copy that file with "refactor copy", there is no problem.

这在 Netbeans 中发生在我身上。在 netbeans 中,当您尝试在没有“重构副本”的情况下复制同一目录中的 .java 文件时,它会将新文件放置为“YourJavaFile_1.java”并出现问题。但是,如果您使用“重构副本”复制该文件,则没有问题。

It gives the name as "YourJavaFile1.java", but with refactoring.

它的名称为“YourJavaFile1.java”,但进行了重构。

回答by Hyman

Just try putting a super()at the beginning of your constructor as the error states.

只需尝试将 asuper()放在构造函数的开头作为错误状态。

I thought it was usually inferred and added without the constraint to write it, maybe the superclass of CostOperationsdoesn't have any empty constructor..

我认为它通常是在没有约束的情况下推断和添加的,也许它的超类CostOperations没有任何空构造函数..

回答by Travis

Verified: Compiler Bug.

已验证:编译器错误。

回答by 14inc

I opine it may be caused as a result in class/constructor access specifier mismatch. I just resolved a similar issue where the class was declared with a package access specifier but its constructor was declared public.

我认为这可能是由于类/构造函数访问说明符不匹配造成的。我刚刚解决了一个类似的问题,该类是用包访问说明符声明的,但它的构造函数被声明为 public。

Simply making the constructor also have a package access specifier resolved the issue.

简单地让构造函数也有一个包访问说明符就解决了这个问题。

class Ngram{

    public Ngram(String str, int count){
        ngram = str;
        freq = count;
    }

    String ngram;
    int freq;
}