Search code examples
androidoncreate

Error in msg in Android programming log.d


I created my method onClick listener to log a simple massage in the log but All of logs like Log.d is not among the suggested methods indicated by hitting the ctrl+enter. i do import android.util.log. and msg is red and show a error

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.newlayout);

    btn1=findViewById(R.id.firstButton);
    btn2=findViewById(R.id.secondButton);

    btn1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Log.d(TAG,  msg: "onClick ");
        }
    });

}

}


Solution

  • You are trying to convey message in Log. but this isnt the right way to use Log.d in android. You can use Log like this as shown below

    Log.d("TAG","msg: Onclick")
    

    This is how you can use Log in android you have to type msg into double quotes to print it in console. if you want to print any variable value into Log you can write like this:

    Log.d("TAG","msg: $onclick")
    

    here onclick is the variable name you want to print. Thanks