'TAG' has private access in 'android.support.v4.app.FragmentActivity'

安稳与你 提交于 2019-12-03 01:25:29

You should define a constant for your tag in MainActivity:

private static final String TAG = "MainActivity"

try the following

private static final String TAG = MainActivity.class.getSimpleName();

You can use this field in your any Activity or Fragment.

Well that's just an Android's way of telling us that we haven't defined TAG. To define the TAG in the current file, we can go to MainActivity Class and type "logt", you will get some auto code suggestions from Android studio, press enter there and you will get following code

private static final String TAG = "MainActivity";

Once you add this to your code, your error will be gone

Practical note: following is the better approach

private static final String TAG = MainActivity.class.getSimpleName();

as compared to:

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