简体   繁体   English

处理java.lang.VerifyError

[英]Handling java.lang.VerifyError

I have written a Java Program using Lucene in Eclipse Juno. 我已经在Eclipse Juno中使用Lucene编写了Java程序。 Whenever I try to run it, it is giving the following errors: 每当我尝试运行它时,它都会出现以下错误:

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)

and source of the error ie the line in BuildManinIndex.java is: 错误的来源,即BuildManinIndex.java中的行是:

        doc.add(new IntField("startTime1",startTime1,Field.Store.YES));

Here startTime1 is a field in document to be indexed. 这里的startTime1是文档中要索引的字段。 I was earlier using Lucene 3.6.0 and now I am using Lucene 4.3.0. 我之前使用的是Lucene 3.6.0,现在使用的是Lucene 4.3.0。 I have not imported any thing from java.net.URL. 我没有从java.net.URL导入任何东西。 I have no clue of the possible cause of this error. 我不知道此错误的可能原因。 Please help. 请帮忙。

EDIT: This following short program I have written. 编辑:这是我编写的以下简短程序。

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();

The error message is a bit confusing because you are not inheriting the IntField class, you are creating an instance of it, right? 错误消息有点令人困惑,因为您没有继承IntField类,而是在创建它的实例,对吗?

doc.add(new IntField("startTime1", startTime1, Field.Store.YES));

The problem is in the first part of that statement doc.add(..) . 问题出在该语句的第一部分doc.add(..) There was a change to the Document class between Lucene versions 3.6.0 and 4.x - add(..) in 3.6 is accepting Fieldable ( class API ), and in 4.1.0 is accepting IndexableField ( class API ). 有一个变化的Document Lucene的版本3.6.0和4.x之间类- add(..)在3.6正在接受Fieldable类API ),并在4.1.0正在接受IndexableField类API )。

Useful article on the VerifyError . 关于VerifyError有用文章 Or this StackOverflow answer . 或者这个StackOverflow答案

Also, there is no IntField in Lucene 3.6.0, ie the class is from Apache Solr ( class API ) but there is one in Lucene 4.1.0. 此外,在Lucene 3.6.0中没有IntField ,即该类来自Apache Solr( 类API ),但是在Lucene 4.1.0中只有一个。 You are probably using the 3.6 version of IntField which is not the same as Lucene's - please check your import statements and your classpath. 您可能正在使用IntField的3.6版本,该版本与Lucene的版本不同-请检查您的import语句和类路径。

UPDATE UPDATE

Joy, the easiest solution for you is to remove the old Lucene JAR files from /home/abhishek/mtp/stage-2/software/apache-tomcat-7.0.37/lib and put the new ones, and Refresh the project in Eclipse. Joy,最简单的解决方案是从/home/abhishek/mtp/stage-2/software/apache-tomcat-7.0.37/lib删除旧的Lucene JAR文件,然后将新文件放置在Eclipse中,然后刷新该项目。

My advice for you is to switch to Apache Maven for dependency management (there is a Maven plug-in for Eclipse). 我的建议是切换到Apache Maven进行依赖关系管理(有一个Eclipse的Maven插件)。 In Eclipse you create a "New Maven Project" and add the dependencies to pom.xml file - an example for Lucene . 在Eclipse中,您创建一个“ New Maven Project”,并将依赖项添加到pom.xml文件中(这是Lucene示例) This way you don't have to copy any JAR files into your project or Tomcat. 这样,您不必将任何JAR文件复制到项目或Tomcat中。

Good luck. 祝好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM