I’m using Lucene APIs, and I get the following error on this line of my code:
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.Fieldable;
...
Document _document = new Document();
_document.add(new Field("type", document.getType()));
Error:
CollectionIndexer.java:34: cannot find symbol
symbol : method add(org.apache.lucene.document.Field)
location: class CollectionIndexer.Document
_document.add(new Field(“type”, document.getType()));
This is the documentation about the method:
http://lucene.apache.org/java/3_0_3/api/all/org/apache/lucene/document/Document.html#add(org.apache.lucene.document.Fieldable)
thanks
Update: javac -cp commons-digester-2.1/commons-digester-2.1.jar:lucene-core-3.0.3.jar myApp.java
The problem comes from the fact that your
document.getType()method returns a String and thereis no constructor in the
Fieldclass that matches your call.See http://lucene.apache.org/java/3_0_3/api/all/org/apache/lucene/document/Field.html.
If I test your code in my environment Eclipse says:
Maybe you could do as the following:
UPDATE after source code submission ——————–
The problem comes from the fact that in your class you have an inner-class called Document. There is a name conflict between your Document class and the Lucene’s one. When you instanciate your document with the line
Document _document = new Document();you’re actually instanciating YOUR Document class. That’s why the compiler cannot find theaddmethod.Multiple solution:
a. Instanciate the Document prefixing it with the Lucene package name
b. Rename your inner class so that you don’t have any name conflict.