views:

190

answers:

3

Hello All,

I am using HC APACHE.
I have added both httpcore-4.0.1.jar and httpclient-4.0.1.jar in the classpath of netbeans.

I am getting error:
java.lang.NoClassDefFoundError: org/apache/http/impl/client/DefaultHttpClient

My Code is as follows. Please help.

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) {
        }

    }
}
A: 

httpclient-4.0.1.jar contains org.apache.http.impl.client.DefaultHttpClient check your classpath for typos.

stacker
OK I got it work by adding path of DefaultHttpClient to felix.properties
Pujan Srivastava
Thanks for help
Pujan Srivastava
A: 

Just to point out NoClassDefFoundError and NoClassFoundException are not the one and the same thing?

You might want to look into Demystified class loading problem series.

All the best.

Adeel Ansari
NoClassDefFoundError:Yes it was NoClassDefFoundErrorThanks for help. problem is solved.
Pujan Srivastava
A: 

This exception happened because of Felix did not find the actual class as it was not included the import. THanks all for answering this.

Pujan Srivastava