我确信有一些简单的修复我只是没有看到,但出于某种原因,以下代码:
private HttpClient httpclient = new DefaultHttpClient();
HttpParams httpParameters = new BasicHttpParams();
int timeoutConnection = 3000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
int timeoutSocket = 5000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
private Gson gson = new Gson();
给出语法错误,如:http://i.imgur.com/JF8zxPG.png
请帮助,我不知道为什么这些在语法上不正确,它试图告诉我我需要删除括号。
答案 0 :(得分:0)
您试图在类体中调用函数(setConnectionTimeout()
),而不是在方法体中调用。
将HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
和HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
移动到某个方法(示例中的构造函数),例如:
private HttpClient httpclient = new DefaultHttpClient();
public void initialize () {
HttpParams httpParameters = new BasicHttpParams();
int timeoutConnection = 3000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
int timeoutSocket = 5000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
}
// rest of the code
此外,为什么需要两个HttpClient
?