简体   繁体   English

在Android上的“ onCreate”方法中的问题

[英]issue in 'onCreate' method on android

Before everything, I apologize, my question might seems silly. 在此之前,我深表歉意,我的问题似乎很愚蠢。 I'm a beginer with the making of android software. 我是制作android软件的初学者。 I'm seeking help because i have got no idea where the problem comes from. 我正在寻求帮助,因为我不知道问题出在哪里。

public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d("debug", "I'm not going to appear on the LogCat ;_;");
        SomeStaticClass.something();
        setContentView(R.layout.activity_main);
    }

    //called from a button in activity_main.xml
    public void hello (View view) {
        Log.d("debug", "but for some reasons I will");
    }
}

as you can see the first Log.d in the onCreate function is never called. 如您所见,永远不会调用onCreate函数中的第一个Log.d Or it never appear in the LogCat I don't now. 或者它永远不会出现在我现在不知道的LogCat中。 Here is my probleme, because of this, I don't know if SomeStaticClass.something() is ever called ! 这是我的问题,因此,我不知道是否曾经调用过SomeStaticClass.something() Does anyone now why or has an idea ? 现在有人为什么或有想法吗? Thank you. 谢谢。

(edit) thank you in the comment :-). (编辑)谢谢您的评论:-)。 yes the breakpoint was a great idea ( I really feel ashamed that i didn't figured that one by myself ... ). 是的,断点是一个好主意(我真的很as愧我没有一个人想到这个……)。 So yes, the function is called, yet, Log.d still (4 times on 5) not show anything but only in the onCreate(Bundle savedInstanceState) . 因此,是的,该函数已被调用,但Log.d仍然(5的4倍)仅在onCreate(Bundle savedInstanceState)不显示任何内容。 It is not much of a problem anymore now that I know it works, i'll marked it as solved. 现在我知道它可以工作了,这不再是一个大问题,我将其标记为已解决。 Yet, just by curiosity, does anyone knows why log.d doesn't write anything ? 但是,仅仅出于好奇,有人知道为什么log.d不写任何东西吗?

Logcat is set to Verbose log level by default. 默认情况下,Logcat设置为详细日志级别。 This means that you can either use Log.v instead of Log.d or switch to Debug log level in Logcat. 这意味着您可以使用Log.v代替Log.d或在Logcat中切换到“调试”日志级别。

okay, I have a always working answer. 好吧,我有一个始终有效的答案。 I just need to replace Log.d("what", "ever"); 我只需要替换Log.d("what", "ever"); by System.out.println("whatever"); 通过System.out.println("whatever"); . The reason is still unclear but it doesn't matter anymore. 原因尚不清楚,但不再重要。 I'm terribly sorry for taking your time and bothering you all. 非常抱歉,您抽出宝贵时间并打扰大家。 Thank you all for the help. 谢谢大家的帮助。

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

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