java.lang.NoSuchFieldError: DEF_CONTENT_CHARSET

java.lang.NoSuchFieldError: DEF_CONTENT_CHARSET(java.lang.NoSuchFieldError: DEF_CONTENT_CHARSET)

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

问题描述

我正在尝试运行 java 程序,但出现以下运行时错误.错误如下所示.

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

"main" java.lang.NoSuchFieldError: DEF_CONTENT_CHARSET 的原因是什么

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

我下载了 http-core-4.1-alpha 因为那是包含org/apache/http/params/SyncBasicHttpParams 类 来自 findjar.com.所以那个版本的http-core是没有商量余地的.如何找到那个版本的http-core兼容的httpclient版本?

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?

推荐答案

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

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

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

... 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.

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

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.

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

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:java.lang.NoSuchFieldError: DEF_CONTENT_CHARSET

基础教程推荐