编程语言
首页 > 编程语言> > Android获取Java类名/文件名/方法名/行号

Android获取Java类名/文件名/方法名/行号

作者:互联网

    /**
     * Android打印方法路径
     */
    public static void printMethodPath() {
        //new 一个异常类
        Exception exception = new Exception();
        //调用者上级类名
        Log.i(TAG, "Class0———>:" + exception.getStackTrace()[0].getClassName());
        //调用者上级的上级类名
        Log.i(TAG, "Class1———>:" + exception.getStackTrace()[1].getClassName());
        //调用者上级的方法名
        Log.i(TAG, "MethodName0———>:" + exception.getStackTrace()[0].getMethodName());
        //调用者上级的上级方法名
        Log.i(TAG, "MethodName1———>:" + exception.getStackTrace()[1].getMethodName());
        //当前方法行号
        Log.i(TAG, "line0———>:" + exception.getStackTrace()[0].getLineNumber());
        //调用方法行号
        Log.i(TAG, "line1———>:" + exception.getStackTrace()[1].getLineNumber());
    }

标签:exception,Java,Log,getStackTrace,TAG,Android,上级,类名,调用者
来源: https://www.cnblogs.com/mjtabu/p/12111013.html