I am using Apache Lucene
for tokenizing string in Java and I am encountering the below error even after importing all the external jar files.
The error is:
The method addAttribute(Class) is undefined for the type TokenStream
The line of code in which the error occured:
CharTermAttribute charTermAttri=stream.addAttribute(CharTermAttribute.class);
The code is:
public static ArrayList<String> tokenizeString(Analyzer analyzer, String string) {
ArrayList<String> result = new ArrayList<String>();
try {
TokenStream stream = analyzer.tokenStream(null, new StringReader(string));
**CharTermAttribute charTermAttri = stream.addAttribute(CharTermAttribute.class);**
stream.reset();
while (stream.incrementToken()) {
result.add(stream.getAttribute(CharTermAttribute.class).toString());
}
stream.close();
} catch (IOException e) {
// not thrown b/c we're using a string reader...
throw new RuntimeException(e);
}
return result;
}