java.lang.NoSuchFieldError: DEF_CONTENT_CHARSET
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18246979/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.lang.NoSuchFieldError: DEF_CONTENT_CHARSET
提问by liv2hak
I am trying to run a java program and I am getting the following run time error.The error is shown below.
我正在尝试运行一个 java 程序,但出现以下运行时错误。错误如下所示。
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
"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?
我下载了,http-core-4.1-alpha
因为那是包含org/apache/http/params/SyncBasicHttpParams class
从 findjar.com的 jar
。所以那个版本的 http-core 是不可协商的。我如何找出与那个版本的 http-core 兼容的 httpclient 版本?
采纳答案by Jon Skeet
You've got two different versions of httpcore in your classpath:
您的类路径中有两个不同版本的 httpcore:
~/.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 moreversions around.
...虽然第二个实际上是CLASSPAHT
根据您的问题导出的。我们也不知道您的lib
目录中有什么- 可能还有更多版本。
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 onlyusing 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.
除了一个被注释掉之外,还会有两个版本的 httpclient。我建议您解决所有这些问题,以便您只使用两个库的最新版本。我的猜测是,实际使用的是一种版本的 httpclient 和一种版本的 httpcore,它们不兼容。要么是这样,要么就在 httpcore 中,从一个 jar 文件中获取了一些清单条目,但是当要求一个类时,它会获取另一个。
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.
您还应该确保您使用的 httpcore 版本适合您使用的 httpclient 版本。例如,我刚刚下载了最新版本的 httpclient (4.2.5),它使用了 httpcore 4.2.4。如果您尝试将 httpclient-4.2 与 httpcore-4.1 一起使用,那可能不兼容。