views:

192

answers:

2

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) {
        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?

+1  A: 

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.

vkraemer
+1  A: 

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.

Stephen C
Could it be the fact that I have two versions of the jar that contains the MaxentTagger class? I'm checking that theory right now
piggles
That could be it. But also try fixing the `getMessage()`
Stephen C
Apologies, but the code was in the middle of being changed when I pasted it. I was printing all the stuff before.
piggles