为什么 logcat 在我的 Android 中不显示任何内容?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2250112/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 05:09:29  来源:igfitidea点击:

Why doesn't logcat show anything in my Android?

androideclipselogginglogcat

提问by TIMEX

Why doesn't logcatshow anything in my Android (while developing apps with Eclipse)?

为什么logcat在我的 Android中不显示任何内容(使用 Eclipse 开发应用程序时)?

It just doesn't print anything. It's empty.

它只是不打印任何东西。它是空的。

采纳答案by Nikola Smiljani?

回答by MoMo

I had this same issue but my fix was much more basic:

我遇到了同样的问题,但我的修复方法更为基本:

If the LogCat panel is empty in Eclipse the emulator doesn't have the focus. Go to the DDMS perspective and try clicking on the 'emulator' entry in the Devices panel (top-left screen).

如果 Eclipse 中的 LogCat 面板为空,则模拟器没有焦点。转到 DDMS 透视图并尝试单击“设备”面板(左上角屏幕)中的“模拟器”条目。

回答by denispyr

Dial

拨号

*#*#2846579#*#*

and you will see a hidden menu. Go to the Project Menu > Background Setting > Log setting and define the log availability (log switch) and level (log level setting).

你会看到一个隐藏的菜单。转到项目菜单 > 背景设置 > 日志设置并定义日志可用性(日志切换)和级别(日志级别设置)。

Please note this may apply to Huawei phones onlyas is stated for an Ideos X3 (here) and is tested at a Honor U8860.

请注意,这可能仅适用于华为手机,如 Ideos X3(此处)所述,并在 Honor U8860 上进行了测试。

回答by fyodorananiev

If clicking in Devices panel doesn't bring the spam, use reset adbin dropout menu from triangle on the right of the snapshot button.

如果单击设备面板不会带来垃圾邮件,请reset adb在快照按钮右侧的三角形下拉菜单中使用。

回答by Nick Kahn

I have the same problem on/off and the way I solved is by File>>Restart (restart the eclipse)

我在开/关时遇到了同样的问题,我解决的方法是通过 File>>Restart(重新启动 eclipse)

回答by Justin Buser

While the answer provided by MoMo will resolve the problem temporarily it will most likely reoccur the next time you launch Eclipse, or launch on a different Emulator/Device.

虽然 MoMo 提供的答案将暂时解决该问题,但它很可能会在您下次启动 Eclipse 或在不同的模拟器/设备上启动时再次出现。

Instead of always having to select my device in the devices view I've found a better solution is to go into your Eclipse preferences and navigate to Android -> LogCat in the list on the left and then enable "Monitor logcat for messages from applications in workspace".

与其总是在设备视图中选择我的设备,我发现更好的解决方案是进入您的 Eclipse 首选项并导航到左侧列表中的 Android -> LogCat,然后启用“监控来自应用程序的消息的 logcat”工作区”。

This way no matter what device you are using logcat will automatically start showing output from it as soon as the application launches.

这样,无论您使用什么设备,logcat 都会在应用程序启动后自动开始显示它的输出。

It will also setup a filter that ensures that only output from your application is displayed, which you can reuse / disable as needed.

它还将设置一个过滤器,确保只显示应用程序的输出,您可以根据需要重用/禁用它。

Logcat application output enabling setting

Logcat 应用程序输出启用设置

回答by Roland

Maybe the log is not enabled in your device. Try to run the following command.

也许您的设备中未启用日志。尝试运行以下命令。

adb shell
echo 1 > /sys/kernel/logger/log_main/enable

回答by masarapmabuhay

OK. This is how I got it to work. I first followed MoMo's advice, that is...

好的。这就是我让它工作的方式。我首先听从了 MoMo 的建议,那就是……

If the LogCat panel is empty in Eclipse the emulator doesn't have the focus. Go to the DDMS perspective and try clicking on the 'emulator' entry in the Devices panel (top-left screen).

如果 Eclipse 中的 LogCat 面板为空,则模拟器没有焦点。转到 DDMS 透视图并尝试单击“设备”面板(左上角屏幕)中的“模拟器”条目。

But to no avail.

但无济于事。

I then attempted to reset adb(Android Debug Bridge) as suggested by furikuretsu. How? Window -> Devices -> upside down triangle menu button -> Reset adb.

然后我尝试reset adb按照 furikuretsu 的建议(Android Debug Bridge)。如何?窗口 -> 设备 -> 倒三角菜单按钮 -> 重置 adb。

It also didn't work, but I did get the following message:

它也不起作用,但我确实收到了以下消息:

Android hierarchyviewer: Unable to get the focused window from device

Androidhierarchyviewer:无法从设备获取焦点窗口

This meant that MoMo was right in that my Android device or emulator didn't have focus. However, the solution I did in my case is different.

这意味着 MoMo 是正确的,因为我的 Android 设备或模拟器没有焦点。但是,我在我的情况下所做的解决方案是不同的。

What worked for me:

什么对我有用:

1) Replugged my Android device, which was connected to my computer via USB.

1) 重新插入通过 USB 连接到我的计算机的 Android 设备。

2) Restarted Eclipse, as mentioned by Abu Hamzah (although since I didn't know I can do File -> Restart, I manually closed down Eclipse, and then restarted the application again.)

2) 重新启动 Eclipse,正如 Abu Hamzah 所提到的(虽然因为我不知道我能做什么File -> Restart,我手动关闭了 Eclipse,然后再次重新启动了应用程序。)

I can now see logs in my logcat.

我现在可以在我的 logcat 中看到日志。

Hope this helps you too.

希望这对你也有帮助。

回答by Chris Lacy

The simplest solution worked for me: Shutdown and restart my phone and Eclipse alike.

最简单的解决方案对我有用:关闭并重新启动我的手机和 Eclipse。

回答by Mahesh

I think, you haven't selected device or emulator , on which running your application,

我认为,您还没有选择在其上运行应用程序的设备或模拟器,

In eclipse go to DDMS Perspectiveand select device or emulator on which you are running your application.

在 Eclipse 中,转到DDMS Perspective并选择运行应用程序的设备或模拟器。

(Note: No need to restart the Eclipse)

(注意:不需要重启Eclipse)