lucene Java,找不到符号:方法methodName(org.bla.blabla.myClass)
我正在使用Lucene API,在这行代码中出现以下错误:
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()));
错误: 收藏索引。java:34:找不到符号 符号:方法添加(org.apache.lucene.document.Field) 位置:class CollectionIndex。文件 _文件。添加(新字段(“type”,document.getType())
谢谢
更新:javac-cpcommons-digester-2.1/commons-digester-2.1。jar:lucene-core-3.0.3。jarmyapp。爪哇
# 1 楼答案
当我被这类错误难倒时,通常是因为我有两个
InterfaceName
的定义,并且意外地在一个或多个地方导入了错误的定义(例如,在自动导入缺少的类时,我意外地选择了
java.awt.List
而不是java.util.List
。)确保
。。。与预期的包/类匹配
# 2 楼答案
根据问题的更新进行更新:
commons-digester-2.1
,以消除可能的冲突李># 3 楼答案
问题来自这样一个事实:
document.getType()
方法返回一个字符串,然后 在Field
类中没有与调用匹配的构造函数。 见http://lucene.apache.org/java/3_0_3/api/all/org/apache/lucene/document/Field.html如果我在我的环境中测试您的代码,Eclipse会说:
也许你可以这样做:
提交源代码后更新
问题来自这样一个事实:在类中有一个名为Document的内部类。文档类与Lucene的类之间存在名称冲突。当您使用
Document _document = new Document();
行实例化文档时,实际上是在实例化文档类。这就是编译器找不到add
方法的原因多种解决方案:
a.实例化以Lucene包名称作为前缀的文档
重命名内部类,这样就不会有任何名称冲突