简体   繁体   中英

Android Log cannot resolve

I have this line in my android class but not inside an method.

Log.v("Scan Class", "Excecuted");

on the letter v following the period I recieve an error "Cannot resolve symbol 'v'". I have imported android.util.log; and am not sure what is creating this error. Thank you in advance.

Use a static initializer :

static 
{
    Log.v("Scan Class", "Excecuted");
}

This will print when your class is loaded. Classes within your app will generally be loaded as Android starts your application.

You can put Log on below stages:

on onCreate() :

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


        Log.v("Scan Class", "Excecuted");

       // Other stuff
}

In method :

private void checkLog(){
    Log.v("Scan Class", "Excecuted");
}

In function :

private String funcStr(){
    Log.v("Scan Class", "Excecuted");
    return "test";
}

Hope it will help you.

You are calling a method .But to call method here you need to add it in constructor or static block or onCreate of activity or something like that . This is because it should have some starting point like in Java we have main method as stating point .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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