我有以下代码,如本教程所示:http://developer.android.com/training/volley/simple.html
final TextView mResponse = (TextView) findViewById(R.id.response);
RequestQueue queue = Volley.newRequestQueue(this);
String url = "http://www.example.com/";
// Request a string response from the provided URL.
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener() {
@Override
public void onResponse(String response) {
// Display the first 500 characters of the response string.
mResponse.setText("Response is: "+ response.substring(0,500));
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
mResponse.setText("That didn't work!");
}
});
然而,尽管在匿名Listener类中实现了onResponse()方法,但Response.Listener以红色加下划线,给出以下错误:“'从Listener派生的匿名类'必须要么被声明为abstract或者在'Listener'中实现抽象方法'onResponse(T)'。我不确定为什么它没有看到我完全做到了。
答案 0 :(得分:1)
Response.Listener是一种泛型类型。你必须指定:
new Response.Listener<String>()
答案 1 :(得分:0)
compile 'dev.dworks.libs:volleyplus:+'
compile 'com.android.volley:volley:1.0.0'
使用两个库时会出现此问题。要解决此问题,请删除
compile 'com.android.volley:volley:1.0.0'
您的代码可以正常使用。