Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot resolve symbol 'tag'

Tags:

java

android

I am beginner in learning android java. I learning the java android tutorial from Youtube and I follow exactly the coding from the video, but my coding showing "cannot resolve symbol 'tag' " on the android studio. May I know what is the problem? and hope to get explanation from all the master here.

package com.NewApplicationLifeCycle;

import ...

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.i( tag: "State", msg: "onCreate" );
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.i( tag: "State", msg: "onStart" );
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.i( tag: "State", msg: "onResume" );
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.i( tag: "State", msg: "onPause" );
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.i( tag: "State", msg: "onStop" );
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.i( tag: "State", msg: "onRestart" );
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.i( tag: "State", msg: "onDestroy" );
    }
}
like image 416
Machine_Z Avatar asked Oct 20 '25 14:10

Machine_Z


2 Answers

IDEs give you more context about the parameters of the function you're calling by highlighting the parameter names. Like in this case Log.i(tag: String, msg: String) accepts two parameters tag and msg but you don't have to write them yourself when calling the function.

Remove tag: and msg: from Log.i(...) calls and call it like this:

Log.i( "State", "onRestart" );

and so on for others as well.

like image 158
Osama A.Rehman Avatar answered Oct 23 '25 03:10

Osama A.Rehman


use like this

var tag = "your tag name"
var msg = "you message"

Log.i( tag +"State", msg+ "onCreate" );

otherwise :-

Log.d(tag, message)

Log.i( "your tag name","your message" );
  • and check this official link
    how can i Write and View Logs with Logcat

like image 39
Sandeep Pareek Avatar answered Oct 23 '25 04:10

Sandeep Pareek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!