繁体   English   中英

凌空android示例代码中的错误

[英]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.

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