java.lang.NoSuchFieldError:DEF_CONTENT_CHARSET [英] java.lang.NoSuchFieldError: DEF_CONTENT_CHARSET

查看:388
本文介绍了java.lang.NoSuchFieldError:DEF_CONTENT_CHARSET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行java程序,我收到以下运行时错误。错误如下所示。

 线程main中的异常java.lang.NoSuchFieldError:DEF_CONTENT_CHARSET 
org.apache.http.impl.client.DefaultHttpClient.setDefaultHttpParams(DefaultHttpClient.java:175)
at org.apache.http。 impl.client.DefaultHttpClient.createHttpParams(DefaultHttpClient.java:158)
at org.apache.http.impl.client.AbstractHttpClient.getParams(AbstractHttpClient.java:448)
at org.apache.http。 impl.client.AbstractHttpClient.createClientConnectionManager(AbstractHttpClient.java:309)
at org.apache.http.impl.client.AbstractHttpClient.getConnectionManager(AbstractHttpClient.java:466)
at org.apache.http。 impl.client.AbstractHttpClient.createHttpContext(AbstractHttpClient.java:286)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:851)
at org.apache.http。 impl.client.AbstractHttp Client.execute(AbstractHttpClient.java:805)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:784)
at net.floodlightcontroller.core.internal.PacketStreamerClient。 registerForPackets(PacketStreamerClient.java:90)
at net.floodlightcontroller.core.internal.PacketStreamerClient.main(PacketStreamerClient.java:51)

现在我添加到类路径的文件如下。

  export CLASSPATH = $(JARS =(./ LIB / *罐)。 IFS = :; echo$ {JARS [*]})
export CLASSPATH = $ CLASSPATH:〜/ .m2 / repository / org / apache / httpcomponents / httpclient / 4.0.1 / httpclient-4.0.1.jar
export CLASSPATH = $ CLASSPATH:〜/ .m2 / repository / org / apache / httpcomponents / httpcore / 4.0.1 / httpcore-4.0.1.jar
export CLASSPATH = $ CLASSPATH:〜/ .m2 / repository / commons-logging / commons-logging / 1.1.1 / commons-logging-1.1.1.jar
export CLASSPAHT = $ CLASSPATH:〜/ ms_thesis / ONOS / httpcore-4.1.jar
#export CLASSPATH = $ CLASSPATH:〜/ ms_thesis / ONOS / lib / httpclient-4.2.jar
export CLASSPATH = $ CLASSPATH:〜/ google-gson-2.2.4 / gson-2.2.4.jar

mainjava.lang.NoSuchFieldError:DEF_CONTENT_CHARSET



<的原因是什么? p>我下载了 http-core-4.1-alpha ,因为那是包含
的jar org / apache / http / params / SyncBasicHttpParams来自findjar.com的class 。那个版本的http-core是不可协商的。我如何找到与该版本的http-core兼容的httpclient版本?

解决方案

你的类路径中有两个不同版本的httpcore:

 〜/ .m2 / repository / org / apache / httpcomponents / httpcore / 4.0.1 / httpcore-4.0.1.jar 
~ / ms_thesis / ONOS / httpcore-4.1.jar

...虽然第二个实际上根据您的问题导出为 CLASSPAHT 。我们也不知道 lib 目录中的内容 - 甚至可能有更多版本。



还有两个版本的httpclient,除了一个被注释掉。我建议你将所有这些排序,以便你只使用两个库的最新版本 。我的猜测是实际被拾取的是一个版本的httpclient和一个版本的httpcore,它们是不兼容的。要么就是这样,要么只是在httpcore中,有一些清单条目从一个jar文件中被选中,但是当一个类被要求它获取另一个时。



无论哪种方式,在您的类路径中同时拥有两个版本的同一个库只是一个坏主意。



您还应该确保您使用的httpcore版本适合于您使用的httpclient版本。例如,我刚刚下载了最新版本的httpclient(4.2.5),它使用的是httpcore 4.2.4。如果您尝试将httpclient-4.2与httpcore-4.1一起使用,则可能不兼容。


I am trying to run a java program and I am getting the following run time error.The error is shown below.

Exception in thread "main" java.lang.NoSuchFieldError: DEF_CONTENT_CHARSET
    at org.apache.http.impl.client.DefaultHttpClient.setDefaultHttpParams(DefaultHttpClient.java:175)
    at org.apache.http.impl.client.DefaultHttpClient.createHttpParams(DefaultHttpClient.java:158)
    at org.apache.http.impl.client.AbstractHttpClient.getParams(AbstractHttpClient.java:448)
    at org.apache.http.impl.client.AbstractHttpClient.createClientConnectionManager(AbstractHttpClient.java:309)
    at org.apache.http.impl.client.AbstractHttpClient.getConnectionManager(AbstractHttpClient.java:466)
    at org.apache.http.impl.client.AbstractHttpClient.createHttpContext(AbstractHttpClient.java:286)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:851)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:784)
    at net.floodlightcontroller.core.internal.PacketStreamerClient.registerForPackets(PacketStreamerClient.java:90)
    at net.floodlightcontroller.core.internal.PacketStreamerClient.main(PacketStreamerClient.java:51)

Now the files that I have added to the classpath are the following.

export CLASSPATH=$(JARS=(./lib/*.jar); IFS=:; echo "${JARS[*]}")
export CLASSPATH=$CLASSPATH:~/.m2/repository/org/apache/httpcomponents/httpclient/4.0.1/httpclient-4.0.1.jar
export CLASSPATH=$CLASSPATH:~/.m2/repository/org/apache/httpcomponents/httpcore/4.0.1/httpcore-4.0.1.jar
export CLASSPATH=$CLASSPATH:~/.m2/repository/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar
export CLASSPAHT=$CLASSPATH:~/ms_thesis/ONOS/httpcore-4.1.jar
#export CLASSPATH=$CLASSPATH:~/ms_thesis/ONOS/lib/httpclient-4.2.jar
export CLASSPATH=$CLASSPATH:~/google-gson-2.2.4/gson-2.2.4.jar

What is the reason for "main" java.lang.NoSuchFieldError: DEF_CONTENT_CHARSET

I downloaded http-core-4.1-alpha as that is the jar that contains org/apache/http/params/SyncBasicHttpParams class from findjar.com. So that version of http-core is not negotiable.How do I find out the version of httpclient that is compatible with that version of http-core?

解决方案

You've got two different versions of httpcore in your classpath:

~/.m2/repository/org/apache/httpcomponents/httpcore/4.0.1/httpcore-4.0.1.jar
~/ms_thesis/ONOS/httpcore-4.1.jar

... although the second one is actually exported as CLASSPAHT according to your question. We also don't know what's in your lib directory - there could be even more versions around.

There would also be two versions of httpclient, except one is commented out. I suggest you sort all of this out so that you're only using the latest versions of both libraries. My guess is that what's actually being picked up is one version of httpclient and one version of httpcore, and they're not compatible. Either that, or just within httpcore there's some manifest entry being picked up from one jar file, but then when a class is asked for it's getting the other.

Either way, having two versions of the same library in your classpath at a time is simply a bad idea.

You should also make sure that the version of httpcore that you use is appropriate for the version of httpclient you use. For example, I've just downloaded the latest version of httpclient (4.2.5) and it uses httpcore 4.2.4. If you're trying to use httpclient-4.2 with httpcore-4.1, that may not be compatible.

这篇关于java.lang.NoSuchFieldError:DEF_CONTENT_CHARSET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆