为什么我在 Logcat 中看不到我的打印语句?
我尝试在我的第一个 Android 程序上调试代码。我开始使用常规 println,它在早期的 main(onCreate) 方法中工作,在 LogCat 中显示结果。然而,它似乎在下面不起作用,所以然后我开始尝试计算 Log.i/Log.d 但没有成功。我基本上是想看看程序是否实际运行下面的方法 - 尽管 LogCat 中没有生成打印语句,但我认为当我点击应用程序上的“new”或“exit”按钮时,代码实际上正在运行,它似乎到达了 case 语句中的正确位置并运行 finish();
任何有关将某些内容打印到 LogCat 的帮助将非常感激,这样我就可以看到发生了什么。
谢谢埃德
·瑞安
public void onClick(final View v) {
System.out.println("Here in - onClick");
switch (v.getId()) {
case R.id.about_button:
System.out.println("Here in - onClick1");
Intent i = new Intent(this, About.class);
startActivity(i);
break;
case R.id.new_button:
System.out.println("Here in - onClick2");
finish();
//openNewGameDialog();
break;
case R.id.exit_button:
Log.i("onDisabled","info");
Log.d(TAG, "onDisabled");
System.out.println("Here in - onClick3");
finish();
break;
}
}
}//end class
I trying to debug code on my first Android program. I started using the regular println and it worked in the earlier main(onCreate) method, showing the results in LogCat. However, it doesn't seem to work below, so then I started trying to work out Log.i/Log.d to no sucess. I'm basically trying to see if the program actually runs the below method - although no print statements are produced in the LogCat, I think the code is actually running as when I hit the "new" or "exit"button on my app, it seems to fo to the correct place in the case statement and runs finish();
Any help with would be really appreciated in getting something printed to LogCat, so I can see what's going on.
Thank you
Ed Ryan
public void onClick(final View v) { System.out.println("Here in - onClick"); switch (v.getId()) { case R.id.about_button: System.out.println("Here in - onClick1"); Intent i = new Intent(this, About.class); startActivity(i); break; case R.id.new_button: System.out.println("Here in - onClick2"); finish(); //openNewGameDialog(); break; case R.id.exit_button: Log.i("onDisabled","info"); Log.d(TAG, "onDisabled"); System.out.println("Here in - onClick3"); finish(); break; } } }//end class
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我在 Eclipse 中使用 LogCat 时就经历过这种情况。
当设备掉线或失去焦点时,或者当您使用 2 个或更多不同的设备/模拟器进行调试时,就会发生这种情况。
请尝试以下操作:
I've experienced this while using LogCat within Eclipse.
This happens when the device drops off or loses focus or when you're debugging using 2 or more different devices/emulators.
Try the following:
如果一切都失败了:
我做了上述所有事情,但无法找出问题所在,
测试:
以找出我的条目实际上在 logcat 中,但这是 adt 的怪癖。
修复:
这是唯一修复它的方法。
If all else fails:
I did all the above things and couldn't figure out what was wrong,
Test with:
to figure out that my entries were infact in logcat, but twas adt's quirks.
Fix:
This was the only thing that fixed it.
杰里米·爱德华兹走在正确的道路上。您需要打开 DDMS 透视图并单击您的设备名称。然后回到你的主要视角。有时日志仍然没有显示您想要看到的内容,因此请选择 logcat 上方带圆圈的“V”。这将显示 logcat 的详细模式。否则,您可以使用 i 或 d 对其进行过滤,它们分别与 Log.i 或 Log.d 关联。接下来,滚动到 logcat 底部以查看来自设备的最新消息。
Jeremy Edwards is on the right track. You need to open the DDMS perspective and click your device's name. Then go back to your main perspective. Sometimes the log is still not showing what you want to see, so select the circled "V" above the logcat. This will display the logcat's verbose mode. Otherwise, you can filter it using i or d, which associate with Log.i or Log.d, respectively. Next, scroll to the bottom of the logcat to see the most recent messages from the device.
对杰里米回答的一个澄清。在他说的提示上...
它立即对我不起作用,但在我这样做之后并进入:
并单击设备旁边的框,它工作正常。我不确定是否需要删除设备和选中该框,或者仅选中该框就足够了,但我想只要它有效就可以了。
One clarification on Jeremy's answer. On the tip where he said...
It didn't work for me right away but after I did that and went into:
and clicked the box next to the device it worked fine. I am not sure if both the deleting of devices and checking the box were required, or if just checking the box would have been enough but I guess as long as it works its all good.
如果您尝试在 Eclipse 中查看 AVD 的输出,有时 Eclipse 和模拟器会断开连接。通常,如果您发出这些命令,事情就会清楚:
打开“设备”视图并确保您看到您的设备/AVD。
If you're trying to see the output of an AVD in Eclipse, sometimes Eclipse and the emulator get disconnected. Usually if you issue these commands, things will clear up:
Open up the Devices view and be sure that you see your device/AVD.