Android Studios doesn't understand Log function

我们两清 提交于 2021-02-18 20:43:53

问题


I'm fairly new to android programming in general, and I'm having problems with printing to my log. I'm using Log.v() to do it, but I get an error: "cannot resolve symbol v"

This is the code:

import android.util.Log;
public class DressDatabase {
    Dress[] dresses;
    private static final String TAG = "Testing: ";

    public DressDatabase(){
        dresses = new Dress[15];
    }

    Log.v(TAG, "String");
}

回答1:


Try this:

import android.util.Log;
public class DressDatabase {
    Dress[] dresses;
    private static final String TAG = "Testing: ";

    public DressDatabase(){
        dresses = new Dress[15];
        Log.v(TAG, "String");
    }

}



回答2:


This is being caused as Log function cannot identify the tag and msg while you type. Once you finished with your instruction, check if the error message still pops up, if so press Alt+Enter. It will resolve. Check out my screenshot.Click here to view my screenshot




回答3:


Use Alt+Enter on top of Log function to add an import clause at the top of your class if you don't have it yet.

This error message "cannot resolve" can also be caused by the Log function needing two parameters (instead of one):

Log.v("param1", "param2");

You can also add logging info by using these shortcuts:

Type logt and Enter to create a TAG for your class:

private static final String TAG = "mytag";

Type logd and Enter to create a debug log (or logi, logv, etc):

Log.d(TAG, "my logging message");


来源:https://stackoverflow.com/questions/16987788/android-studios-doesnt-understand-log-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!