Question

I have an ArrayList with some strings, and, for every string, I remove the stopwords and add it to a new ArrayList.

But, Netbeans returns an error:

"AWT-EventQueue-0" java.lang.NoSuchFieldError: LUCENE_47

...

at
org.apache.lucene.analysis.standard.StandardTokenizer.init(StandardTokenizer.java:144)
at
org.apache.lucene.analysis.standard.StandardTokenizer.<init>(StandardTokenizer.java:132)

The code to send the string is:

for(i=0;i<listR.size();i++){
    str=listR.get(i);
    try {
        str=st.StopWordString(str);
        listSt.add(str);
    } catch (IOException ex) {
        Logger.getLogger(PanelAuto.class.getName()).log(Level.SEVERE, null, ex);
    }
}

And the method I use to remove the stopwords is:

public String StopWordString(String incoming) throws IOException{

    Tokenizer tokenizer = new StandardTokenizer(Version.LUCENE_44,new StringReader(incoming));

    final StandardFilter standardFilter = new StandardFilter(Version.LUCENE_44, tokenizer);
    final StopFilter stopFilter = new StopFilter(Version.LUCENE_44, standardFilter, StopAnalyzer.ENGLISH_STOP_WORDS_SET);

    final CharTermAttribute charTermAttribute = tokenizer.addAttribute(CharTermAttribute.class);

    stopFilter.reset();
    while(stopFilter.incrementToken()) {
        final String token = charTermAttribute.toString().toString();
        list.add(token);
    }

    for(i=0; i<list.size(); i++){
     str += list.get(i)+" ";
    } 

    return str;
}

The error is thrown on this line:

Tokenizer tokenizer = new StandardTokenizer(Version.LUCENE_44,new StringReader(incoming));
Was it helpful?

Solution

It looks like you have mismatched versions of the Lucene jars in your classpath. Particularly, it appears you have lucene-analyzers.common-4.7.X.jar, but an earlier version of lucene core (perhaps lucene-core-4.4.X.jar?). You have set the tokenizer to use an earlier algorithm, but you still need to use jars from the same version of Lucene. I believe this is the particular line which directly causes the issue, which gives an example of why that is:

if (matchVersion.onOrAfter(Version.LUCENE_47))

(The Version class lives in lucene-core)

If you've upgraded lucene-core to version 4.7 already, you may have an old jar in your classpath that you need to remove.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top