get Trace Info - Android App

Android examples for App:Log

Description

get Trace Info

Demo Code


//package com.java2s;

public class Main {
    public static String getTraceInfo(int i) {
        StackTraceElement astacktraceelement[] = Thread.currentThread()
                .getStackTrace();/*from  w w w .j a  v  a 2s  .  c om*/
        if (astacktraceelement == null || astacktraceelement.length < i + 1
                || astacktraceelement[i] == null) {
            return null;
        } else {
            return (new StringBuilder()).append("[Line:")
                    .append(astacktraceelement[i].getLineNumber())
                    .append(", Method:")
                    .append(astacktraceelement[i].getMethodName())
                    .append("]").toString();
        }
    }

    public static int getLineNumber() {
        StackTraceElement astacktraceelement[] = Thread.currentThread()
                .getStackTrace();
        if (astacktraceelement == null || astacktraceelement.length < 4
                || astacktraceelement[1] == null) {
            return -1;
        } else {
            return astacktraceelement[3].getLineNumber();
        }
    }

    public static String getMethodName() {
        StackTraceElement astacktraceelement[] = Thread.currentThread()
                .getStackTrace();
        if (astacktraceelement == null || astacktraceelement.length < 4
                || astacktraceelement[1] == null) {
            return null;
        } else {
            return astacktraceelement[3].getMethodName();
        }
    }
}

Related Tutorials