【问题标题】:Strange Log.i() behavior Android Studio奇怪的 Log.i() 行为 Android Studio
【发布时间】:2020-09-23 02:54:14
【问题描述】:

我看到了一些非常奇怪的东西。我正在发出 http 发布请求

        HttpClient httpClient = new DefaultHttpClient();
        HttpResponse response = null;
        try {
            response = httpClient.execute(httpPost);
            HttpEntity entity = response.getEntity();
            String strResponse = null;
            if (entity != null) {
                strResponse = EntityUtils.toString(entity);
                Log.i("SetupAutoCardResponse",String.valueOf(strResponse));
                Log.i("otherTest","test");
                Log.i("otherTest",strResponse);
                return true;
            }
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }

我在日志中看到的唯一输出是otherTest : Test。 带有strResponse 的日志根本不显示,我的意思是,没有任何显示。它看起来不像 SetupAutoCardResponse : nullotherTest: null。绝对什么都没有出现。但我知道我得到了回应。表达式返回true

【问题讨论】:

  • 你能在你的 logcat 窗口中检查哪个过滤器(例如,详细或错误)
  • @Rajesh 我尝试了一堆,但它不应该在信息中。这不是i 的用途吗?
  • @MohammadZarei 你能解释一下吗?

标签: java android logging


【解决方案1】:

在 Log 中,如果 Message 为 Null 或 Blank 或 Empty,Log 将不会记录下来。 示例:Log.i(TAG, MSG); 为了确保它有效,我们可以在 MSG 中添加一些文本

 Log.i(TAG, String.format("%s %s", "MSG>" , MSG));

【讨论】:

  • 谢谢。好资料。原来我们的strResponse 没有被分配。 android studio 不是问题,但 HttpPost 响应确实是空的。对我来说仍然是个问题,但这篇文章到此结束。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多