2016年8月18日星期四

解决Eclipse的java代码出错:The import org.apache cannot be resolved

Eclipse中,折腾java代码。把之前在android中的代码拿过来使用。
结果出现The import org.apache cannot be resolved的错误:
The import org apache cannot be resolved
 【解决过程】
1. 去:
project -> Build Path -> Configure Build Path -> Libraries -> Add External Jar’s
但是坑爹的却是,没有说,此处的
org.apache
是属于哪个jar包。
2.既然找不到org.apache
那么,鉴于此处,全部都是:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.CookieStore;
//import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.cookie.Cookie;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.DefaultHttpClient;
//import org.apache.http.impl.cookie.BasicClientCookie;
import org.apache.http.params.HttpParams;
 
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.client.params.ClientPNames;
import org.apache.http.client.protocol.ClientContext;
 
import org.apache.http.util.EntityUtils;
即,全都是:
org.apache.http
那就先去找org.apache.http。
3.参考:
突然想到,貌似这个:
org.apache.http
是对应的android里面的,不是标准的java库中的。
4.所以,去到别人说的,apache官网中找这个库。
搜:
download org.apache.http
HttpClient 4.2.5.zip
解压后,得到:
httpcomponents-client-4.2.5-bin\httpcomponents-client-4.2.5\lib
下面有很多jar:
under httpcomponents-client has many jar
先加进来试试:
project build path add external archiveds
add httpclient and httpcore jar
然后所有的org.apache.http就正常了:
then all org apache http ok