为什么我在 Logcat 中看不到我的打印语句?

发布于 2024-11-09 05:22:58 字数 1091 浏览 0 评论 0原文

我尝试在我的第一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

抹茶夏天i‖ 2024-11-16 05:22:58

我在 Eclipse 中使用 LogCat 时就经历过这种情况。
当设备掉线或失去焦点时,或者当您使用 2 个或更多不同的设备/模拟器进行调试时,就会发生这种情况。

请尝试以下操作:

  1. 转到 DDMS 透视图并双击您正在调试的应用程序或至少双击设备。您应该会看到 LogCat 选项卡充斥着新消息。
  2. 删除除您当前正在使用的设备之外的所有设备。
  3. 再次尝试仅使用 Log.* 函数。
  4. 将 LogCat 过滤器设置为“调试”或“详细”。

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:

  1. Go to the DDMS perspective and double-click the application that you're debugging or at least the device. You should see the LogCat tab flood with the new messages.
  2. Remove all devices except the one you're working with at the moment.
  3. Try just using the Log.* functions again.
  4. Set the LogCat filter to Debug or Verbose.
天气好吗我好吗 2024-11-16 05:22:58

如果一切都失败了:

我做了上述所有事情,但无法找出问题所在,

测试:

adb logcat

以找出我的条目实际上在 logcat 中,但这是 adt 的怪癖。

修复:

重启eclipse

这是唯一修复它的方法。

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.

Fix:

Restart eclipse

This was the only thing that fixed it.

2024-11-16 05:22:58

杰里米·爱德华兹走在正确的道路上。您需要打开 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.

生活了然无味 2024-11-16 05:22:58

对杰里米回答的一个澄清。在他说的提示上...

“删除除您当前正在使用的设备之外的所有设备。”

它立即对我不起作用,但在我这样做之后并进入:

运行>调试配置>目标(右侧选项卡)

并单击设备旁边的框,它工作正常。我不确定是否需要删除设备和选中该框,或者仅选中该框就足够了,但我想只要它有效就可以了。

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.

泪之魂 2024-11-16 05:22:58

如果您尝试在 Eclipse 中查看 AVD 的输出,有时 Eclipse 和模拟器会断开连接。通常,如果您发出这些命令,事情就会清楚:

adb kill-server
adb start-server

打开“设备”视图并确保您看到您的设备/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:

adb kill-server
adb start-server

Open up the Devices view and be sure that you see your device/AVD.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文