[英]Error in volley android sample code
我在android開發人員培訓中收到此示例代碼中的錯誤。 我得到了錯誤
@Override
public void onResponse(String response) {
錯誤為:“方法不會從其超類覆蓋方法”。
所以我不能運行代碼。 如果我注釋掉@override,則可以運行代碼,但是請求沒有任何響應。 請有人能指出我做錯了什么嗎? 我原樣復制了代碼
http://developer.android.com/training/volley/simple.html我是volley的新手,我正在嘗試學習它的工作原理。 完整的代碼如下
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);
}
嘗試將<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){}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.