get Line Number from stack trace element - Android App

Android examples for App:Log

Description

get Line Number from stack trace element

Demo Code


//package com.java2s;

public class Main {
    public static int getLineNumber() {
        StackTraceElement astacktraceelement[] = Thread.currentThread()
                .getStackTrace();// ww  w  . j  a  v  a 2s  . c  o m
        if (astacktraceelement == null || astacktraceelement.length < 4
                || astacktraceelement[1] == null) {
            return -1;
        } else {
            return astacktraceelement[3].getLineNumber();
        }
    }
}

Related Tutorials