java.lang.NoSuchMethodError:org.apache.http.protocol.BasicHttpContext:方法()V未找到

嗨,我想尝试建立一个小的webapp,但我遇到了错误。 以下是我的代码

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); 

我使用的是httpclient-4.0-beta2.jar和httpcore-4.0.1.jar。 看起来BasicHttpContext与我的应用程序中的其他一些jar子发生了冲突,但我无法弄明白。 任何线索将不胜感激。

看起来你有一个带有旧版/新版BasicHttpContext的jar文件。 如果存在直接冲突,则会收到ClassNotFoundException 。 ClassLoader通常是关于这种事情的混蛋。 在这种情况下,类存在但是不具有另一个库(我相信它的调用Context的httpclient)被编译的方法。