java Log.d 在 Logcat Android Studio 中不显示 log.d

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39933315/
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-11-03 04:47:05  来源:igfitidea点击:

Log.d not showing log.d in Logcat Android Studio

javaandroid

提问by P.Yntema

Android studio does not show any Logs I wrote in my code. I have tried putting the log to verbose and debug. I am using 'No filters'. Why is 'Oncreatetestlog' not showing up in my logcat?

Android Studio 不显示我在代码中编写的任何日志。我尝试将日志放入详细信息并进行调试。我正在使用“无过滤器”。为什么“Oncreatetestlog”没有出现在我的 logcat 中?

package com.example.keydown;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        if (savedInstanceState != null) {
            Log.d("Oncreatetestlog", "onCreate() Restoring previous state");
            /* restore state */
        } else {
            Log.d("Oncreatetestlog2", "onCreate() No saved state available");
            /* initialize app */
        }
    }
}

回答by Taras Mykhalchuk

Go to File -> invalidate caches / Restart. And let Android Studio to index your project again. It works for me.

转到文件-> 使缓存无效/重新启动。并让 Android Studio 再次索引您的项目。这个对我有用。

回答by P.Yntema

After hours of searching and trying, I found out it did not have to do with Android Studio, but that my phone didn't allow Logging. See this answerfor more information.

经过数小时的搜索和尝试,我发现它与 Android Studio 无关,而是我的手机不允许登录。有关更多信息,请参阅此答案

回答by Jamie Turner

Alternatively, you could use System.out.println()to show the text in logcat

或者,您可以使用System.out.println()在 logcat 中显示文本

Replace

代替

Log.d("Oncreatetestlog", "onCreate() Restoring previous state");

With

System.out.println("Oncreatetestlog onCreate() Restoring previous state");

回答by Gaurav Lambole

If Log.d is not showing in your Logcat just replace Log.dwith Log.wtfLike this:

如果 Log.d 未显示在您的 Logcat 中,只需替换Log.dLog.wtf如下所示:

Replace:

代替:

Log.d("tag",""+catstr);

With:

和:

Log.wtf("tag",""+catstr);

It Works..happy coding;)

它有效..快乐编码;)