Log Stack Trace - Android android.util

Android examples for android.util:Log

Description

Log Stack Trace

Demo Code

import android.util.Log;

public class Main {

  public static void printStackTrace(String TAG, Throwable ex) {
    StackTraceElement[] sta = ex.getStackTrace();
    if (ex.getMessage() != null) {
      Log.e(TAG, ex.getMessage());/*from w ww. jav a 2s.c  om*/
    }
    Log.e(TAG, ex.getClass().getName());
    for (StackTraceElement st : sta) {
      Log.e(TAG, "   " + st.getFileName() + "." + st.getMethodName() + ": " + st.getLineNumber());
    }
  }

}

Related Tutorials