Android 截取字符串请求响应(侦听器)错误

Android 截取字符串请求响应(侦听器)错误,android,json,android-volley,Android,Json,Android Volley,我正在使用截取字符串的方法,我不知道为什么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.v

我正在使用截取字符串的方法,我不知道为什么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);
}
import com.android.volley.Request;
导入com.android.volley.RequestQueue;
导入com.android.volley.VolleyError;
导入com.android.volley.Response;
导入com.android.volley.toolbox.JsonObjectRequest;
导入com.android.volley.toolbox.StringRequest;
导入com.android.volley.toolbox.volley;
私有void getData(){
//创建字符串请求
StringRequest StringRequest=new StringRequest(Request.Method.GET、Config.DATA\u URL、new Response.Listner(){
@凌驾
公共void onResponse(字符串响应){
JSONObject j=null;
试一试{
//将获取的Json字符串解析为Json对象
j=新的JSONObject(响应);
//将JSON字符串数组存储到我们的JSON数组中
result=j.getJSONArray(Config.JSON_数组);
//调用getStudents方法从JSON数组中获取学生
获取学生(结果);
}捕获(JSONException e){
e、 printStackTrace();
}
}
},
新的Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
}
});
//创建请求队列
RequestQueue RequestQueue=Volley.newRequestQueue(getActivity());
//将请求添加到队列
添加(stringRequest);
}
试试这个(适合我)

final RequestQueue RequestQueue=Volley.newRequestQueue(MainActivity.this);
StringRequest StringRequest=新的StringRequest(Request.Method.POST、serverURL、,
新的Response.Listener(){
@凌驾
公共void onResponse(字符串响应){
//对响应字符串执行一些操作
tv_respuesta.setText(应答);
requestQueue.stop();
}
},
新的Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
//遇到错误时做些什么
tv_respuesta.setText(error.toString());
requestQueue.stop();
}
}
);
添加(stringRequest);

然后发布错误消息。
           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);