我在Android开发人员培训的示例代码中收到错误。我在
上得到了错误@Override
public void onResponse(String response) {
错误是:“方法不会覆盖其超类中的方法”。
所以我无法运行代码。如果我注释掉@override,我可以运行代码但是我没有得到请求的响应。请任何人都能指出我做错了什么?我按原样复制了代码
http://developer.android.com/training/volley/simple.html我是排球的新手,我正在努力学习它是如何运作的。完整代码位于
之下 public void getHttpText(View v){
final TextView mTextView = (TextView) findViewById(R.id.textView22);
mTextView.setText("Check");
// Instantiate the RequestQueue.
RequestQueue queue = Volley.newRequestQueue(this);
String url ="http://www.google.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.
mTextView.setText("Response is: " + response.substring(0, 500));
}
@Override
public void onResponse(Object o) {
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
mTextView.setText("That didn't work!");
}
});
// Add the request to the RequestQueue.
queue.add(stringRequest);
}
答案 0 :(得分:0)
尝试将<String>
放在new Response.Listener
// Request a string response from the provided URL.
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {...
在您的代码中,您似乎不需要public void onResponse(Object o){}