Ошибка ответа на запрос строки залога - PullRequest
0 голосов
/ 13 сентября 2018

Я использую метод GET Volley String, я не знаю, почему Response (Listener) выдает ошибку, а ErrorListener также выдает ошибку. Вот мой код, пожалуйста, помогите мне найти ошибку

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.VolleyError;
import com.android.volley.Response;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;

private void getData(){
    //Creating a string request

    StringRequest stringRequest = new StringRequest(Request.Method.GET,Config.DATA_URL,new Response.Listner<String>() {
                @Override
                public void onResponse(String response) {
                    JSONObject j = null;
                    try {
                        //Parsing the fetched Json String to JSON Object
                        j = new JSONObject(response);

                        //Storing the Array of JSON String to our JSON Array
                        result = j.getJSONArray(Config.JSON_ARRAY);

                        //Calling method getStudents to get the students from the JSON Array
                        getStudents(result);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            },

            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {

                }
            });

            //Creating a request queue
            RequestQueue requestQueue = Volley.newRequestQueue(getActivity());

            //Adding request to the queue
            requestQueue.add(stringRequest);
}

1 Ответ

0 голосов
/ 29 сентября 2018

Попробуй с этим (у меня работает);

           final RequestQueue requestQueue= Volley.newRequestQueue(MainActivity.this);
    StringRequest stringRequest=new StringRequest(Request.Method.POST, serverURL,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    // Do something with response string
                    tv_respuesta.setText(response);
                    requestQueue.stop();
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    // Do something when get error
                    tv_respuesta.setText(error.toString());
                    requestQueue.stop();
                }
            }

    );
    requestQueue.add(stringRequest);
...