英文:
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<20; j++){
Log.d("myTag","hello world");
}
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<20;j++){
Log.d("myTag" + j,"hello world");
}
or
for(int j=0;j<20;j++){
Log.d("myTag","hello world" + j);
}
答案2
得分: 0
也可以看到您在此循环中遇到了相同的问题:
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&lq=1 和 https://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("myTag", "${j/20}")
}
But this loop runs as desired:
for (j in 0..19) {
Log.d("myTag", "$j")
}
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&lq=1 and https://stackoverflow.com/questions/34587273/android-logcat-logs-chatty-module-line-expire-message
专注分享java语言的经验与见解,让所有开发者获益!
评论