Logcat 不显示我的日志调用

发布于 2024-10-03 14:28:58 字数 1098 浏览 1 评论 0原文

我对 Android 编程完全是菜鸟,想学习如何调试我的应用程序。我似乎无法在 LogCat 中显示我的 Log.i|d|v 调用。

这是我正在使用的代码。正如你所看到的,我已经定义了一个 LOG_TAG 常量,但似乎在 LogCat 中找不到它。我还导入了 android.util.Log 并且确保在我的 AndroidManifest 中我已将“debuggable”设置为 TRUE。

我还检查了 http://developer.android.com/reference/android/util /Log.html 解决这个问题没有任何运气。

我做错了什么?我是否找对了地方?我也尝试过使用 DDMS 和调试视角,但没有任何运气。对这个菜鸟的任何帮助将不胜感激。谢谢。

我的环境: 视窗XP IDE = Eclipse 版本:3.6.1,内部版本号:M20100909-0800 模拟器 = 让它指向 android sdk 2.1 api 7

//非常基本的 HELLO World 代码,带有几个 Log.i 调用

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class debugger extends Activity {
    private static final String LOG_TAG = "debugger";

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        Log.i(LOG_TAG, "line 13");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Log.i(LOG_TAG, "CREATING NOW");
    }
}

I'm a total noob at Android programming, and wanted to learn how to debug my apps. I can't seem to have my Log.i|d|v calls displayed in the LogCat.

Here's the code that I'm using. As you can see I have defined a LOG_TAG constant, but can't seem to find it in the LogCat. I have also imported android.util.Log AND I have made sure that in my AndroidManifest I have "debuggable" set to TRUE.

I have also checked http://developer.android.com/reference/android/util/Log.html w/o any luck resolving this issue.

What am I doing wrong? Am I even looking in the right place? I've tried using the DDMS and Debug perspective as well w/o any luck. Any help to this noob would be greatly appreciated. Thanks.

My environment:
Windows XP
IDE = Eclipse Version: 3.6.1, Build id: M20100909-0800
Emulator = having it point to android sdk 2.1 api 7

//very basic HELLO World code with a couple of Log.i calls

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class debugger extends Activity {
    private static final String LOG_TAG = "debugger";

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        Log.i(LOG_TAG, "line 13");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Log.i(LOG_TAG, "CREATING NOW");
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(30

城歌 2024-10-10 14:28:59

其他答案都不适合我,但这确实有效:

我从工作区中删除了我的项目,然后从项目文件夹中删除了以点开头的任何内容(.settings、.project 等)。然后我重新导入了投影。我缺少一些设置和断点,但至少它有效。

None of the other answers worked for me, but this did:

I removed my project from my workspace, then deleted anything that started with a dot (.settings, .project, etc.) from the project folder. Then I re-imported the projected. I'm missing some settings and breakpoints but at least it works.

请恋爱 2024-10-10 14:28:59

我一直遇到这个问题,并且在我将日志调用移至处理程序之前似乎没有任何效果。现在,无论您身在何处,它每次都有效。

I had been experiencing this problem and nothing seemed to work until I moved the log call into a handler. Now it works every time, no matter where you are at.

北斗星光 2024-10-10 14:28:59

我在 logcat 搜索框中输入搜索词时犯了一个错误。
我忘记删除它,因此看不到新日志。因为它们与我的搜索词不匹配并且没有显示。

I made the mistake of typing in a search term in the logcat search box.
I forgot to delete it and hence couldn't see the new logs. Since they didn't match my search term and weren't displayed.

君勿笑 2024-10-10 14:28:59

就我而言,我必须删除这一行:

    <application
         android:debuggable="false"  <!-- Remove this line -->
         ..../>

From Application tag in my Manifest file.

In my case, I had to remove this line:

    <application
         android:debuggable="false"  <!-- Remove this line -->
         ..../>

From Application tag in my Manifest file.

oО清风挽发oО 2024-10-10 14:28:59

对我来说最好的解决方案是重新启动adb服务器(虽然我已经在Android studio - 工具 - Android中启用了ADB集成 - 选中)。为了快速做到这一点,我在 android-sdk\platform-tools 目录(adb.exe 所在位置)中创建了 adbr.bat 文件,如下所示里面:

adb kill-server
adb start-server

因为我在 PATH 系统变量中有这个文件夹,所以当我需要从 Android studio 重新启动 adb 时,我只能写入终端 adbr 并完成。

执行此操作的另一个选项是通过设备选项卡中的 Android 设备监视器 - 单击向右小箭头后的菜单 - 重置 adb

Best solution for me was restart adb server (while I have Enabled ADB integration in Android studio - Tools - Android - checked). To do this quickly I created adbr.bat file inside android-sdk\platform-tools directory (where is adb.exe located) with this inside:

adb kill-server
adb start-server

Because I have this folder in PATH system variable, always when I need restart adb from Android studio, I can write only into terminal adbr and it is done.

Another option to do this is through Android Device Monitor in Devices tab - Menu after click on small arrow right - Reset adb.

南渊 2024-10-10 14:28:59

对于日食:
1)进入ddms视角。
2) 确保选择了正确的设备。
3) 如果已经选择并且不显示日志,则重新启动 ABD。
* 希望这能解决。

For eclipse:
1) Go to ddms perspective.
2) Make sure that correct device is selected.
3) If already selected and not displaying logs, then restart ABD.
* Hope this will solve.

若水般的淡然安静女子 2024-10-10 14:28:59

我还使用“adb usb”重新启动了 ADB 服务,并为我解决了问题。事实上,我只有一项活动不再记录。其他人都做了记录。重新启动 adb 后,一切又恢复正常了。对于正在寻找其他解决方案的其他人:CLI 中的 adb Kill-server、adb start-server 通常也可以解决您的问题。

I restarted the ADB service as well with "adb usb" and fixes the problem for me. In fact, only one of my activities didn't log anymore. All the others did log stuff. After restart adb everything works like a charm again. For the other people who're searching for another solution: adb kill-server, adb start-server in CLI will often fix your problem aswell.

打小就很酷 2024-10-10 14:28:59

让你的应用强制关闭一次
这将再次启动 LogCat ...

使用它来强制关闭:D

setContentView(BIND_AUTO_CREATE);

make your app force close once
this will start LogCat again ...

use this for force close :D

setContentView(BIND_AUTO_CREATE);
荭秂 2024-10-10 14:28:59

有时问题不是来自电脑,另一方面是 IDE、ADB 等,而是由您的设备引起,该设备不向 ADB 发送日志,因此如果您尝试了前面提到的所有方法,但仍然是您的问题logcat 为空尝试重新启动您的设备并重试。我尝试了上面提到的所有方法,但它们都不起作用,但在我的手机上重新启动后 logcat 工作得像魔术一样

some times the problem is not from pc on the other hand IDE,ADB etc, but it arises from your device that doesn't send logs to ADB so if you tried all the ways mentioned before and still your logcat is empty try to restart your device and try again.I tried all the ways mentioned above and neither of them worked but after a restart on my phone logcat worked like magic

一直在等你来 2024-10-10 14:28:59

我有这个问题并已修复,字符串标签没有空格:

“我的标签”//注意显示
“my_tag” // 可以

I have this problems and fixed, String TAG without space:

"my tag" // noting show
"my_tag" // is ok

£烟消云散 2024-10-10 14:28:59

就我而言,我只需向字符串添加一个名称。在第一个例子中,我只是在括号之间有一个空格

private static final String TAG = " ";

,但在添加名称后,它工作得很好。

private static final String TAG = "oncreate";

In my case I just had to add a name to the String. In first instance I just had a space in between the brackets

private static final String TAG = " ";

but after adding a name it worked perfectly.

private static final String TAG = "oncreate";
青衫负雪 2024-10-10 14:28:59

升级到Android 3.6.1后,我多次遇到此问题。
对我来说唯一有效的是重新启动设备。

After upgrade to Android 3.6.1, I have experienced this issue multiple times.
The only thing that works in my case is RESTARTING THE DEVICE.

我纯我任性 2024-10-10 14:28:58

使用 Eclipse 时,在 DDMS 透视图中,确保选择并突出显示正确的设备(可能是 emulator-xxxx)。只有这样你才能在logcat视图中得到logcat输出。

另外,Android 插件有点古怪,有时只显示 logcat 视图中的最后一行。如果发生这种情况,请尝试清除日志。之后,您应该再次获取所有日志条目(无论如何对我有用)。

When using Eclipse, in the DDMS perspective, make sure the correct device (propably emulator-xxxx) is selected and highlighted. Only then will you get the logcat output in the logcat view.

Also, the Android plugin is a bit quircky, and sometimes only shows the last line in the logcat view. If this happens, try to clear the log. After that, you should get all the log entries again (works for me anyway).

朮生 2024-10-10 14:28: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-10-10 14:28:58

我在使用 Android Studio 时遇到了同样的问题,并通过在 LogCat 右上角的选择框中选择“无过滤器”来设法解决。通过这样做,我开始接收 Android 在后台记录到 LogCat 中的所有内容,包括我丢失的 Log 调用。

在此处输入图像描述

I've had the same problem using Android Studio and managed to get around by selecting No Filters in the select box in the top right corner of LogCat. By doing this I started receiving everything Android logs in the background into LogCat including my missing Log calls.

enter image description here

も星光 2024-10-10 14:28:58

重新启动Eclipse并检查日志cat将显示。

Restart Eclipse and check log cat will be displayed.

兮子 2024-10-10 14:28:58

我发现我是自动导入 com.sileria.Log (来自某个库项目)而不是 android.util.Log ,后者是正确的。还要检查您的进口。

I figured out I was automatically importing com.sileria.Log (from some library project) instead of android.util.Log, where the latter was the correct one. Check your imports as well.

旧梦荧光笔 2024-10-10 14:28:58

我注意到 Eclipse 有时会在启动 Android 应用程序时抛出异常,然后 LogCat 停止更新。我通过简单地重新启动 Eclipse 就纠正了这个问题。我不确定您是否尝试过,并且我知道这远非最佳解决方案,但我怀疑 Eclipse 插件仍然有一些错误需要解决。

I've noticed that Eclipse will sometimes throw an exception upon starting an Android app, then LogCat stops updating. I've corrected that by simply restarting Eclipse. I'm not sure if you've tried that and I know it's far from an optimal solution, but I suspect that the Eclipse plugin still has a few bugs to iron out.

感受沵的脚步 2024-10-10 14:28:58

最简单的方法:

检查您的 logcat 窗口 - 右上角暂停按钮 || (暂停接收新的 logcat 消息)

点击几下+最终重新启动 eclipse(通常在我的情况下有效)

Easiest way:

Check in your logcat window - TOP RIGHT corner PAUSE button || (Pause receiving new logcat messages)

Few clicks + eventually restart eclipse (usually works in my case)

雨轻弹 2024-10-10 14:28:58

我需要使用命令 adb usb 重新启动 adb 服务

在此之前,我获得了所有日志记录并能够进行调试,但没有获得我自己的日志行(是的,我正在获取关联的系统日志记录)与我的申请)。

I needed to restart the adb service with the command adb usb

Prior to this I was getting all logging and able to debug, but wasn't getting my own log lines (yes, I was getting system logging associated with my application).

你的心境我的脸 2024-10-10 14:28:58

您可能看不到日志的原因有多种,下面列出了其中大部分原因。以下是检查大多数原因的一些步骤:

  1. 确保您的文件中没有“android:debuggable=”false””
    AndroidManifest.xml
  2. 确保您的 logcat 未暂停并确保滚动到底部
  3. 您的过滤器应该是“无过滤器”或您当前的应用程序
  4. 您在 logcat 设备列表中选择了正确的设备
  5. 如果您没有收到任何消息,请尝试重新启动 adb。您可以在 Android Studio 中通过单击“重新启动”图标来完成此操作,该图标位于 logcat 的打印图标之后,看起来像一个从盒子中伸出的绿色弯曲箭头。如果您没有看到它,请将鼠标悬停在“>>”上当 logcat 太小时,会继续图标菜单。

There are a number of reasons why you might not see logs, most of which are listed below. Here are some steps to check most reasons:

  1. Make sure you don't have 'android:debuggable="false"' in your
    AndroidManifest.xml
  2. Make sure your logcat isn't paused and make sure you are scrolled to the bottom
  3. Your filters should either be 'no filters' or your current app
  4. You have the correct device selected in your logcat devices list
  5. If you're not getting any messages, try restarting adb. You can do that from Android Studio by clicking on the 'restart' icon, it's right after the print icon for logcat and it looks like a green curved arrow coming out of a box. If you don't see it, mouse over the '>>' that continues the icon menu when the logcat is too small.
手心的海 2024-10-10 14:28:58

快速修复。

只需重新启动 eclipse

即可完美运行。

QUICK FIX.

Just restart the eclipse

Works Perfect.

忆悲凉 2024-10-10 14:28:58

在 Android Studio 上:
单击指向右侧的绿色箭头以重新启动日志记录;如果不可见,请单击>>图标来找到它。

On Android Studio:
Click on the green arrow pointing to the right to restart the logging; if it is not visible, click on the >> icons to locate it.

﹎☆浅夏丿初晴 2024-10-10 14:28:58

我也是 Android-Eclipse 的新手。以下是我在 Eclipse 中显示 LogCat 消息所需的步骤:
1:将其添加到调用 logcat 消息的类中:
私有静态最终字符串标记=“MyActivity”; (根据文档此处

2:添加此 Log.i(TAG , "inLayout - 完成");当您想要显示消息时

如果上述方法不起作用,请关闭 Eclipse 并重新启动它并重新运行您的项目。

然后它应该可以工作。

I'm a newb as well to Android-Eclipse. Here's what it took for me to get LogCat messages to display in Eclipse:
1: add this to the class in which the logcat message is called:
private static final String TAG = "MyActivity"; (per the documentation here)

2: add this Log.i(TAG, "inLayout - finished"); when you where you want to display a message

If the above doesn't work, then shutdonw Eclipse and restart it and rerun your project.

It should then work.

赠意 2024-10-10 14:28:58

还有一件事需要注意:

在 logcat 的右上角有一个下拉表,用于按类型过滤消息。确保它处于您正在寻找的级别(如果它处于断言级别,则可能会使您的 logcat 为空)。

There is one more thing to watch for:

On the top right side of the logcat there is a dropdown table for filtering messages by type. Make sure it's on the level you are looking for (if it will be on the assert level, it will likely leave your logcat empty).

森罗 2024-10-10 14:28:58

请转到任务管理器并终止 adb.exe 进程。再次重新启动您的日食。

或者

尝试adb Kill-server然后adb start-server命令。

Please go to Task Manager and kill the adb.exe process. Restart your eclipse again.

or

try adb kill-server and then adb start-server command.

dawn曙光 2024-10-10 14:28:58

可能它不正确,而且有点长,但我通过使用以下方法解决了这个问题(Android Studio):

System.out.println("Some text here");

像这样:

try {
       ...code here...
} catch(Exception e) {
  System.out.println("Error desc: " + e.getMessage());
}

Probably it's not be correct, and a little bit longer, but I solved this problem (Android Studio) by using this:

System.out.println("Some text here");

Like this:

try {
       ...code here...
} catch(Exception e) {
  System.out.println("Error desc: " + e.getMessage());
}
伤感在游骋 2024-10-10 14:28:58

我在这样的案例上花了几个小时。我只看到触摸键日志。而已。问题是……智能手机。重启后就OK了。断开电缆导致问题返回。不得不重新启动它。
看来Android的USB通讯设计得不太好。

I spent several hours on such case. I saw only touch keys logs. Nothing more. Problem was... smarthphone. After restarting was OK. Disconnecting cable caused problem returned. Had to restart it again.
Looks like the Android USB communication is not well designed.

和影子一齐双人舞 2024-10-10 14:28:58

使用 SDK 4.0.3,您必须在调试配置 > 上明确选择它项目>>目标,否则它将永远不会使用 Eclipse Indigo (3.7) 显示。当然,Eclipse 会重新启动。

Using the SDK 4.0.3 you have to explicitly select it on debug configurations > project > target or else it will never show using Eclipse Indigo (3.7). Of course an eclipse restart ensues.

埋葬我深情 2024-10-10 14:28:58

我在 logcat 中查看简单日志输出时也遇到问题。当我安装最新的JDK后,我的问题就解决了。我刚刚设置了一台新的开发机器,只安装了 JRE,并且安装 JDK 对我有用。

I had a problem seeing simple log output in logcat as well. My problem was solved when I installed the latest JDK. I just setup a new development machine and only had the JRE installed and instaling the JDK worked for me.

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