我在 Eclipse Juno 中使用 Lucene 编写了一个 Java 程序。每当我尝试运行它时,它都会出现以下错误:
Exception in thread "main" java.lang.VerifyError: Cannot inherit from final class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
at parser.BuildMainIndex.setUp(BuildMainIndex.java:339)
at parser.luceneDemo.main(luceneDemo.java:10)
错误的来源,即 BuildManinIndex.java 中的行是:
doc.add(new IntField("startTime1",startTime1,Field.Store.YES));
这里 startTime1 是文档中要索引的字段。我之前使用的是 Lucene 3.6.0,现在我使用的是 Lucene 4.3.0。我没有从 java.net.URL 导入任何东西。我不知道此错误的可能原因。请帮忙。
编辑:我编写的以下短程序。
writer=new IndexWriter(directory,new StandardAnalyzer(Version.LUCENE_CURRENT),IndexWriter.MaxFieldLength.UNLIMITED);
Document doc=new Document();
doc.add(new Field("title","XYZ",Field.Store.YES,Field.Index.ANALYZED));
doc.add(new Field("address","ABC Road",Field.Store.YES,Field.Index.ANALYZED));
doc.add(new Field("city","Mumbai",Field.Store.YES,Field.Index.ANALYZED));
doc.add(new IntField("startTime1",900,Field.Store.YES));
doc.add(new IntField("finishTime1",1000,Field.Store.YES));
doc.add(new IntField("startTime2",9999,Field.Store.YES));
doc.add(new IntField("finishTime2",9999,Field.Store.YES));
writer.addDocument(doc);
writer.close();