NoClassDefFoundError:HttpClient 4(APACHE)

时间:2010-05-25 08:38:58

标签: java apache-commons apache-felix

我正在使用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) {
        }    
    }
}

3 个答案:

答案 0 :(得分:1)

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

您可能需要查看Demystified class loading problem series

一切顺利。

答案 1 :(得分:0)

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

答案 2 :(得分:0)

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

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