我的日志信息在安卓上只打印了两次。

huangapple 未分类评论51阅读模式
英文:

My log messages is printing only 2 times in Android

问题

为什么在这个循环中,“hello world”只显示了2次,而不是20次?

for (int j = 0; j < 20; j++) {
    Log.d("myTag", "hello world");
}

请解释一下发生了什么。

英文:

Why in this loop "hello world" is shown just 2 times, not 20 times?

 for(int j=0; j&lt;20; j++){
   Log.d(&quot;myTag&quot;,&quot;hello world&quot;);
 }

Please explain what's going on.

答案1

得分: 0

也许这是因为标签名称或消息相同。似乎不允许超过两条相同的日志。您可以使用:

for (int j = 0; j < 20; j++) {
    Log.d("myTag" + j, "hello world");
}

或者

for (int j = 0; j < 20; j++) {
    Log.d("myTag", "hello world" + j);
}
英文:

Maybe this is because of identical tag names or messages. Seems that it doesn't allow more than two same logs. You can use

for(int j=0;j&lt;20;j++){
    Log.d(&quot;myTag&quot; + j,&quot;hello world&quot;);
 }

or

for(int j=0;j&lt;20;j++){
    Log.d(&quot;myTag&quot;,&quot;hello world&quot; + j);
}

答案2

得分: 0

在logcat中,您可以看到以下这些行,我的日志信息在安卓上只打印了两次。

也可以看到您在此循环中遇到了相同的问题:

for (j in 0..19) {
    Log.d("myTag", "${j/20}")
}

但是这个循环按预期运行:

for (j in 0..19) {
    Log.d("myTag", "$j")
}

显然,Android Studio不会显示相同的日志。同时请查看以下这两个链接:
https://stackoverflow.com/questions/55135203/android-logcat-logs-chatty-module-line-identical-message?noredirect=1&amp;lq=1https://stackoverflow.com/questions/34587273/android-logcat-logs-chatty-module-line-expire-message

英文:

In logcat you can see these lines, 我的日志信息在安卓上只打印了两次。

Also you have the same issue with this loop:

for (j in 0..19) {
            Log.d(&quot;myTag&quot;, &quot;${j/20}&quot;)
        }

But this loop runs as desired:

for (j in 0..19) {
            Log.d(&quot;myTag&quot;, &quot;$j&quot;)
        }

Apparently Android Studio doesn't show identical logs. Also see these two links:
https://stackoverflow.com/questions/55135203/android-logcat-logs-chatty-module-line-identical-message?noredirect=1&amp;lq=1 and https://stackoverflow.com/questions/34587273/android-logcat-logs-chatty-module-line-expire-message

huangapple
  • 本文由 发表于 2020年5月4日 23:59:47
  • 转载请务必保留本文链接:https://java.coder-hub.com/61596437.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定