Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot instantiate the type HttpClient

I have added the .jars to my library and I can also instantiate other classes in the JAR. What gives? I've tried to clean the project etc.

It's a compiler-time error. Eclipse won't let me instantiate it.

I'm importing the correct library, not the sun version, and using the default contructor, specified by their tutorial

HttpClient client = new HttpClient();

(Eclipse, mac, Apache HTTP, "HttpClient 4.0.1 (GA)" downloaded from here)

like image 466
Aymon Fournier Avatar asked Jul 18 '10 19:07

Aymon Fournier


2 Answers

HttpClient is an interface in 4.x, use DefaultHttpClient for instances.

HttpClient httpclient = new DefaultHttpClient();
like image 174
b_erb Avatar answered Sep 24 '22 14:09

b_erb


If you are using 4.3, one way to initialize it is:

CloseableHttpClient httpclient = HttpClients.createDefault();

The quick start guide for 4.3 is located at:

http://hc.apache.org/httpcomponents-client-4.3.x/quickstart.html

like image 29
pablosaraiva Avatar answered Sep 25 '22 14:09

pablosaraiva