简体   繁体   中英

Error in volley android sample code

I am getting an error in this sample code from the android developer training. I get the error on the

@Override

public void onResponse(String response) {

The error is: "Method does not override method from its superclass".

So I cant run the code. If I comment out the @override, I can run the code but I get no response from the request. Please can anyone point me to what I am doing wrong? I copied the code as is from

http://developer.android.com/training/volley/simple.html I am new to volley and I am trying to learn how it works. The full code is below

    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);
    }

Try to put <String> after new Response.Listener

                // Request a string response from the provided URL.
                StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
                        new Response.Listener<String>() {...

And in your code it seems you needn't public void onResponse(Object o){}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM