线程“主”java.lang.NoClassDefFoundError 中的异常:org/apache/commons/codec/DecoderException
Posted
技术标签:
【中文标题】线程“主”java.lang.NoClassDefFoundError 中的异常:org/apache/commons/codec/DecoderException【英文标题】:Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/codec/DecoderException 【发布时间】:2013-03-19 02:36:36 【问题描述】:我尝试通过 Solrj 查询 Solr
这是我的代码
public class ReadFromSolr
public static void main(String[] args) throws MalformedURLException, SolrServerException
String url = "http://localhost:8983/solr";
try
SolrServer server = new CommonsHttpSolrServer(url);
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("qt", "/select");
params.set("q", "name");
QueryResponse response = server.query(params);
System.out.println("response = " + response);
catch (MalformedURLException ex)
ex.printStackTrace();
catch (SolrServerException ex)
ex.printStackTrace();
它给了我一个例外
PS。我的项目中有以下罐子:
**apache - 公共日志记录, *httpclient -4.2 , httpcore 4.2.1, slf4j - api 1.6.2, apache - solr - solrj -1.4.0***
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/codec/DecoderException
at org.apache.commons.httpclient.HttpMethodBase.<init>(HttpMethodBase.java:220)
at org.apache.commons.httpclient.methods.GetMethod.<init>(GetMethod.java:89)
at org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:288)
at org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:243)
at org.apache.solr.client.solrj.request.QueryRequest.process(QueryRequest.java:89)
at org.apache.solr.client.solrj.SolrServer.query(SolrServer.java:118)
at com.gismo.ReadFromSolr.main(ReadFromSolr.java:27)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.codec.DecoderException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
【问题讨论】:
【参考方案1】:你需要在类路径上commons-codec.jar。
【讨论】:
以上是关于线程“主”java.lang.NoClassDefFoundError 中的异常:org/apache/commons/codec/DecoderException的主要内容,如果未能解决你的问题,请参考以下文章
Android 异步操作Android 线程切换 ( 判定当前线程是否是主线程 | 子线程中执行主线程方法 | 主线程中执行子线程方法 )