【发布时间】:2014-10-18 20:17:25
【问题描述】:
我有以下代码,取自本教程: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!");
}
});
但是,尽管在匿名侦听器类中实现了 onResponse() 方法,但 Response.Listener 仍以红色下划线显示,并给出以下错误:“'从侦听器派生的匿名类'必须要么声明为抽象类,要么声明为在“Listener”中实现抽象方法“onResponse(T)”。我不确定为什么它没有看到我确实做到了。
【问题讨论】: