简体   繁体   中英

Unable to run this StrimgRequest Code in android studio 1.5 using volley libraries

I am unable to use StringRequest Function and im getting errors showing Listener is abstract and cannot be instantiated. and also it is showing that

cannot resolve constructor

StringRequest(int,anonymous.com.example.puneet.application10.Response.Listener<String>,anonymous.com.example.puneet.application10.Error.Listener)

I am importing volley library files into the project and placing it in the same folder as the MainActivity.class file in the following code:

StringRequest stringrequest= new StringRequest(StringRequest.Method.POST,insertUrl,new Response.Listener<String>())
                    @Override
                    public void onResponse(String response) {
                        // convert the String response to
                    System.out.println(response);
                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        // Error handling
                        System.out.println("Something went wrong!");
                        error.printStackTrace();
                    }
                })

you can send value using below code

   MyApplication newApp;

  String url ="http://www.example.com";
    StringRequest getRequest = new StringRequest(Request.Method.GET, url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        JSONObject json_Response = new JSONObject(response);

                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    Log.d("responce is", "------>" + response);
                }
            },
            new Response.ErrorListener() {
                public void onErrorResponse(VolleyError error) {
                    Log.e("Checked err error==", "===>" + error);
                    error.printStackTrace();
                }
            }) {
        protected Map<String, String> getParams() {

            Map<String, String> params = new HashMap<>();
            params.put("value name", "value");
            params.put("value name", "value");
            params.put("value name", "value");
            return params;
        }
    };
    newApp.getInstance().addToRequestQueue(getRequest);
}

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