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

Posted 踏步

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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());
    }

以上是关于Android获取Java类名/文件名/方法名/行号的主要内容,如果未能解决你的问题,请参考以下文章