简体   繁体   English

为什么我在Logcat中看不到我的打印报表?

[英]Why can't I see my print statements in Logcat?

I trying to debug code on my first Android program. 我试图在第一个Android程序上调试代码。 I started using the regular println and it worked in the earlier main(onCreate) method, showing the results in LogCat. 我开始使用常规的println,它可以在较早的main(onCreate)方法中工作,并在LogCat中显示结果。 However, it doesn't seem to work below, so then I started trying to work out Log.i/Log.d to no sucess. 但是,它似乎在下面无法使用,因此我开始尝试将Log.i / Log.d修改为成功。 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(); 我基本上是在尝试查看程序是否实际运行以下方法-尽管LogCat中未生成任何打印语句,但我认为代码实际上是按我在应用程序上点击“新建”或“退出”按钮时运行的,似乎可以找到case语句中的正确位置并运行finish();

Any help with would be really appreciated in getting something printed to LogCat, so I can see what's going on. 将任何内容打印到LogCat时,任何帮助都将不胜感激,因此我可以看到发生了什么。

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


I've experienced this while using LogCat within Eclipse. 我在Eclipse中使用LogCat时遇到了这种情况。 This happens when the device drops off or loses focus or when you're debugging using 2 or more different devices/emulators. 当设备掉落或失去焦点时,或者当您使用2个或更多不同的设备/仿真器进行调试时,就会发生这种情况。

Try the following: 请尝试以下操作:

  1. Go to the DDMS perspective and double-click the application that you're debugging or at least the device. 转到DDMS透视图,然后双击要调试的应用程序或至少双击该设备。 You should see the LogCat tab flood with the new messages. 您应该看到LogCat标签充满新消息。
  2. Remove all devices except the one you're working with at the moment. 删除除您当前正在使用的设备以外的所有设备。
  3. Try just using the Log.* functions again. 再次尝试仅使用Log。*函数。
  4. Set the LogCat filter to Debug or Verbose. 将LogCat筛选器设置为“调试”或“详细”。

If all else fails: 如果一切都失败了:

I did all the above things and couldn't figure out what was wrong, 我做了以上所有事情,却不知道出了什么问题,

Test with: 测试:

adb logcat

to figure out that my entries were infact in logcat, but twas adt's quirks. 弄清楚我的输入在logcat中是真实的,但是那是adt的怪癖。

Fix: 固定:

Restart eclipse 重新开始蚀

This was the only thing that fixed it. 这是修复它的唯一方法。

One clarification on Jeremy's answer. 澄清杰里米的答案。 On the tip where he said... 在他说过的小费...

"Remove all devices except the one you're working with at the moment." “删除当前正在使用的设备以外的所有设备。”

It didn't work for me right away but after I did that and went into: 立即对我不起作用,但是在我这样做之后进入:

Run > Debug Configurations > target (tab on the right) 运行>调试配置>目标(右侧选项卡)

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. 我不确定是否需要删除设备并选中该框,还是仅需选中该框就足够了,但是我想只要它能正常工作就行了。

Jeremy Edwards is on the right track. 杰里米·爱德华兹走在正确的轨道上。 You need to open the DDMS perspective and click your device's name. 您需要打开DDMS透视图并单击设备名称。 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. 有时日志仍未显示您想要查看的内容,因此请在日志猫上方选择带圆圈的“ V”。 This will display the logcat's verbose mode. 这将显示logcat的详细模式。 Otherwise, you can filter it using i or d, which associate with Log.i or Log.d, respectively. 否则,您可以使用分别与Log.i或Log.d关联的i或d对其进行过滤。 Next, scroll to the bottom of the logcat to see the most recent messages from the device. 接下来,滚动到logcat的底部以查看来自设备的最新消息。

If you're trying to see the output of an AVD in Eclipse, sometimes Eclipse and the emulator get disconnected. 如果您试图在Eclipse中查看AVD的输出,则有时Eclipse和仿真器会断开连接。 Usually if you issue these commands, things will clear up: 通常,如果您发出以下命令,事情将会清除:

adb kill-server
adb start-server

Open up the Devices view and be sure that you see your device/AVD. 打开设备视图,并确保您看到设备/ AVD。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM