开发者

Using the Stanford postagger in java, getting java.lang.IncompatibleClassChangeError

开发者 https://www.devze.com 2022-12-16 04:01 出处:网络
I am trying to initialize the Stanford NLP Part of Speech tagger and I keep getting a java.lang.IncompatibleClassChangeError.When I print the cause of the error, I get null, when I print the message I

I am trying to initialize the Stanford NLP Part of Speech tagger and I keep getting a java.lang.IncompatibleClassChangeError. When I print the cause of the error, I get null, when I print the message I get Implementing Class.

This is my code:

    try {
        MaxentTagger tagger = new MaxentTagger(path+"left3words-wsj-0-18.tagger");
        Reader reader = new BufferedReader(new InputStreamReader(System.in));
        List<Sentence<? extends HasWord>> sentences = MaxentTagger.tokenizeText(reader);
        for (Sentence<? extends HasWord> sentence : sentences) {
            Sentence<TaggedWord> tSentence = MaxentTagger.tagSentence(sentence);
            System.out.println(tSentence.toString(false));
        }

    } catch (IOException e) {
       开发者_如何学JAVA System.err.println("READ ERROR");
        e.printStackTrace();
    } catch (Exception e) {
        System.err.println("TAGGER ERROR");
        e.getMessage();
    } catch(java.lang.IncompatibleClassChangeError e){
        e.getStackTrace();
    }

}

Does anyone know how to fix this?


An IncompatibleClassChangeError happens when some class X has been compiled against one version of some other class Y, and then an attempt is made to load it with a different (incompatible) version of the class Y. If you are getting this error rather than a subtype, it probably means that Y has changed from an interface to a class or vice-versa, or that there has been a change in its inherited interfaces and implemented classes.

The reason that you are not seeing any getMessage() output is that IncompatibleClassChangeError is a subtype of lava.lang.Error not java.lang.Exception. Therefore the catch for Exception is not catching it. Simply copying the println(e.getMessage()) line to the next catch block should fix this.

When you print the exception message, it should tell you more about what is causing the problem. But the root cause is that you need to recompile and/or make sure that you are using the same library JAR files at compile time and runtime.


This question reads like a dup of another stackoverflow question. The answer to that question seems to have been pretty popular, so it is likely to be helpful.

As an aside: you should verify that the classes that are used to compile your app are the classes that are used to run the app.

0

精彩评论

暂无评论...
验证码 换一张
取 消