The type Enum is not generic; it cannot be parameterized with arguments <RestClient.RequestMethod>
I've this error in the following code ..
我在下面的代码中有这个错误。
package ayanoo.utility;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Vector;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import android.util.Log;
public class RestClient {
public enum RequestMethod
{
GET,
POST
}
private Vector <NameValuePair> params;
private String url;
private int responseCode;
private String message;
private String response;
public String getResponse() {
return response;
}
public String getErrorMessage() {
return message;
}
public int getResponseCode() {
return responseCode;
}
public RestClient(String url)
{
this.url = url;
params = new Vector<NameValuePair>();
}
public void AddParam(String name, String value)
{
params.add(new BasicNameValuePair(name, value));
}
public void Execute(RequestMethod method) throws IOException
{
switch(method) {
case GET:
{
//add parameters
String combinedParams = "";
if(!params.isEmpty()){
combinedParams += "/";
for(NameValuePair p : params)
{
//String paramString = p.getName() + "=" + p.getValue();
String paramString = p.getValue();
if(combinedParams.length() > 1)
{
combinedParams += "&" + paramString;
}
else
{
combinedParams += paramString;
}
}
}
Log.d("URL See:",url + combinedParams);
URL urlObject = new URL(url + combinedParams);
//URL urlObject = new URL("http://www.aydeena.com/Services/Search.svc/JSON/SearchByText/1");
executeRequest(urlObject);
break;
}
case POST:
{
HttpPost request = new HttpPost(url);
//add headers
if(!params.isEmpty()){
request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
}
executeRequest(request, url);
break;
}
}
}
private void executeRequest(URL urlObject) throws IOException{
HttpURLConnection con = null;
con = (HttpURLConnection) urlObject.openConnection();
con.setReadTimeout(10000 /* milliseconds */);
con.setConnectTimeout(15000 /* milliseconds */);
con.setRequestMethod("GET");
//con.addRequestProperty("Referer",
// "http://www.pragprog.com/titles/eband/hello-android");
con.setDoInput(true);
// Start the query
con.connect();
response = convertStreamToString(con.getInputStream());
Log.d("Response:", response);
}
private void executeRequest(HttpUriRequest request, String url)
{
HttpClient client = new DefaultHttpClient();
Log.d("Test URL:", url);
HttpResponse httpResponse;
try {
httpResponse = client.execute(request);
responseCode = httpResponse.getStatusLine().getStatusCode();
message = httpResponse.getStatusLine().getReasonPhrase();
HttpEntity entity = httpResponse.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
response = convertStreamToString(instream);
// Closing the input stream will trigger connection release
instream.close();
}
} catch (ClientProtocolException e) {
client.getConnectionManager().shutdown();
e.printStackTrace();
} catch (IOException e) {
client.getConnectionManager().shutdown();
e.printStackTrace();
}
}
private static String convertStreamToString(InputStream is) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
}
what's the problem ??? !
有什么问题? ? ?!
5 个解决方案
#1
3
Are you sure the Java compiler is set to 1.5 (default for android) or better? If you are using Eclipse you can see that from the preferences.
你确定Java编译器设置为1.5 (android默认)还是更好?如果您正在使用Eclipse,您可以从首选项中看到这一点。
#2
5
I had the same problem, and it turned out that it was because the standard lib was not in the eclipse class path for the project. Just go into Build Path -> Add Libraries and add the JRE System Library
我遇到了同样的问题,结果是由于标准库没有在eclipse类路径中进行项目。只需进入构建路径—添加库并添加JRE系统库
#3
0
I had the same problem.
我也有同样的问题。
I only had one error in my project which was the "is not generic one'.
我的项目中只有一个错误,那就是“不是通用的”。
After I commented out the Enum code I found a lot more errors.
在我注释了Enum代码之后,我发现了很多错误。
There seemed to be some kind of hold-up. Only after fixing the other errors and then removing the comments did it work.
好像有什么耽搁了。只有在修复其他错误并删除注释之后,它才会工作。
#4
0
My project named A was just working fine until today but also the closing the project A and running other project B in the emulator im gonna call C, after running properly just closing B in the package explorer and reopening the dammaged one (A) fixed it, as a lil' background I have to say that the previous day while I was coding both projects I was messing with the <uses-sdk android:minSdkVersion="..
tag in the manifest of the project B the one I used today to help me with the dammaged one A, but yesterday when I compiled B and run a new emulator called D just created to run an older system version, as soon as D started, it was shutted down n' powered off(but the thing with D is due to the mess I have for laptop x)), all of this cuz' I was trying to make a non supported by an older API method to work xD.. so probably versioning triggered this issue in my case
我的项目命名只是工作正常,直到今天还关闭项目A和B在模拟器运行其他项目我要叫C,B在package explorer运行正常后就关闭,重启dammaged(A)固定它,作为一个背景lil '我不得不说,前一天我编码两个项目是干扰< uses-sdk android:minSdkVersion = " . .标记的清单项目B今天我使用dammaged一个来帮我,但是昨天当我B编译并运行一个名为D刚刚创建的新模拟器运行旧的系统版本,一旦D开始,关闭了n的断电(但是D是由于混乱我对笔记本电脑x)),所有这一切都因为“我想做一个不支持的一个年长的API方法xD工作. .所以在我的例子中,版本控制可能引发了这个问题
#5
0
Yes I also saw this error message for a project that was previously working fine.
是的,我还看到了这个错误消息,是关于一个以前运行良好的项目。
I checked the compiler version (I am using 1.6) as well as the system library (it is already being used) to no avail.
我检查了编译器版本(我正在使用1.6版本)和系统库(已经在使用),但没有任何用处。
Finally I just closed the project and then re-opened it, and then the problem went away. Sounds like an Eclipse bug to me.
最后我结束了这个项目,然后重新打开它,然后问题就解决了。对我来说,这听起来像是一个Eclipse bug。
#1
3
Are you sure the Java compiler is set to 1.5 (default for android) or better? If you are using Eclipse you can see that from the preferences.
你确定Java编译器设置为1.5 (android默认)还是更好?如果您正在使用Eclipse,您可以从首选项中看到这一点。
#2
5
I had the same problem, and it turned out that it was because the standard lib was not in the eclipse class path for the project. Just go into Build Path -> Add Libraries and add the JRE System Library
我遇到了同样的问题,结果是由于标准库没有在eclipse类路径中进行项目。只需进入构建路径—添加库并添加JRE系统库
#3
0
I had the same problem.
我也有同样的问题。
I only had one error in my project which was the "is not generic one'.
我的项目中只有一个错误,那就是“不是通用的”。
After I commented out the Enum code I found a lot more errors.
在我注释了Enum代码之后,我发现了很多错误。
There seemed to be some kind of hold-up. Only after fixing the other errors and then removing the comments did it work.
好像有什么耽搁了。只有在修复其他错误并删除注释之后,它才会工作。
#4
0
My project named A was just working fine until today but also the closing the project A and running other project B in the emulator im gonna call C, after running properly just closing B in the package explorer and reopening the dammaged one (A) fixed it, as a lil' background I have to say that the previous day while I was coding both projects I was messing with the <uses-sdk android:minSdkVersion="..
tag in the manifest of the project B the one I used today to help me with the dammaged one A, but yesterday when I compiled B and run a new emulator called D just created to run an older system version, as soon as D started, it was shutted down n' powered off(but the thing with D is due to the mess I have for laptop x)), all of this cuz' I was trying to make a non supported by an older API method to work xD.. so probably versioning triggered this issue in my case
我的项目命名只是工作正常,直到今天还关闭项目A和B在模拟器运行其他项目我要叫C,B在package explorer运行正常后就关闭,重启dammaged(A)固定它,作为一个背景lil '我不得不说,前一天我编码两个项目是干扰< uses-sdk android:minSdkVersion = " . .标记的清单项目B今天我使用dammaged一个来帮我,但是昨天当我B编译并运行一个名为D刚刚创建的新模拟器运行旧的系统版本,一旦D开始,关闭了n的断电(但是D是由于混乱我对笔记本电脑x)),所有这一切都因为“我想做一个不支持的一个年长的API方法xD工作. .所以在我的例子中,版本控制可能引发了这个问题
#5
0
Yes I also saw this error message for a project that was previously working fine.
是的,我还看到了这个错误消息,是关于一个以前运行良好的项目。
I checked the compiler version (I am using 1.6) as well as the system library (it is already being used) to no avail.
我检查了编译器版本(我正在使用1.6版本)和系统库(已经在使用),但没有任何用处。
Finally I just closed the project and then re-opened it, and then the problem went away. Sounds like an Eclipse bug to me.
最后我结束了这个项目,然后重新打开它,然后问题就解决了。对我来说,这听起来像是一个Eclipse bug。