无法在控制台上打印字符串

时间:2018-01-10 11:56:10

标签: android android-volley

我可以从服务器获取JSON响应,但它不在控制台上打印。

我正在使用Volley库。

public class DataFetch {
    public void getSellers(final int pageNumber, final Context context) {
        final SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
        String url = BASE_URL + GET_SELLERS_LIST + "?page=" + pageNumber;
        RequestQueue queue = Volley.newRequestQueue(context);

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

                           JSONObject jsonObject = new JSONObject(response);
                           System.out.print("*******\n" + response);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                //Display Error Toast
                Toast.makeText(context, error.toString(), Toast.LENGTH_LONG).show();

            }
        }) {
            public Map<String, String> getHeaders() {
                Map<String, String> params = new HashMap<>();
                params.put(AUTHORIZATION, "Token " + prefs.getString(TOKEN, ""));
                return params;
            }
        };


        // Add the request to the RequestQueue.
        queue.add(stringRequest);
    }
}
调试期间

response可用。

image1

但它没有在控制台上打印出来。

enter image description here

1 个答案:

答案 0 :(得分:1)

您需要替换:

System.out.print("*******\n" + response);

使用:

System.out.println("*******")
System.out.println(response);

据我所知,控制台无法在一个打印声明中打印2行。

(如果有人知道的话我会很乐意收回我的答案)

相关问题