【问题标题】:NoClassDefFoundError: HttpClient 4 (APACHE)NoClassDefFoundError: HttpClient 4 (APACHE)
【发布时间】:2010-05-25 08:38:58
【问题描述】:

我正在使用 apache http commons 4.我在 netbeans 的类路径中添加了 httpcore-4.0.1.jar 和 httpclient-4.0.1.jar。我收到错误:
java.lang.NoClassDefFoundError: org/apache/http/impl/client/DefaultHttpClient

我的代码如下。请帮忙。

import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;

public class HttpClientManager {
    public HttpClient httpclient;
    public HttpClientManager() {
        this.init();
    }

    public void init() {
        try {
            httpclient = new DefaultHttpClient();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void getCourseList() {
        String url = "http://exnet.in.th/api.php?username=demoinst&ha=2b62560&type=instructor";
        HttpGet httpget = new HttpGet(url);

        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        try {
            String responseBody = httpclient.execute(httpget, responseHandler);
            System.out.println(responseBody);

        } catch (Exception e) {
        }    
    }
}

【问题讨论】:

    标签: java apache-commons apache-felix


    【解决方案1】:

    只是指出NoClassDefFoundErrorNoClassFoundException 不是一回事吗?

    您可能想查看Demystified class loading problem series

    一切顺利。

    【讨论】:

    • NoClassDefFoundError:是的,它是 NoClassDefFoundError 感谢您的帮助。问题解决了。
    【解决方案2】:

    httpclient-4.0.1.jar 包含 org.apache.http.impl.client.DefaultHttpClient 检查您的类路径是否有拼写错误。

    【讨论】:

    • 好的,我通过将 DefaultHttpClient 的路径添加到 felix.properties 来实现它
    【解决方案3】:

    这个异常发生是因为 Felix 没有找到实际的类,因为它没有包含在导入中。 感谢大家回答这个问题。

    好的,我通过将 DefaultHttpClient 的路径添加到 felix.properties 来实现它——

    【讨论】:

      猜你喜欢
      • 2010-12-19
      • 1970-01-01
      • 1970-01-01
      • 2012-03-25
      • 1970-01-01
      • 2016-10-29
      • 1970-01-01
      • 2019-10-21
      • 2016-07-04
      相关资源
      最近更新 更多