Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
540 views
in Technique[技术] by (71.8m points)

httpclient - java.lang.NoSuchMethodError: org.apache.http.protocol.BasicHttpContext: method <init>()V not found

Hi I am trying to put up a small webapp but I am getting above error. Below is my code

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("SomeURL"); // Using a URL local to my machine
// after setting nameValuePair and setting it on httppost
httppost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));

// This is where I am getting the above mentioned exception
HttpResponse response = httpclient.execute(httppost);

I am using httpclient-4.0-beta2.jar and httpcore-4.0.1.jar. It looks like BasicHttpContext is getting conflicted with some other jars in my app, but I couldn't figure it out. Any clue will be appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It looks like you have a jar file with an old/newer version of BasicHttpContext. If there was a direct conflict, you'd receive a ClassNotFoundException. ClassLoaders are typically jerks about this kind of thing. In this case, the class exists however does not have the method that another library (I believe it's httpclient that's invoking the Context) was compiled against.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...