
As you see, these are all stack trace elements. I only want the yellow part that have blue fonts (clickable to identify the java class and its line number where the exception was thrown) to be printed as the rest of the stack traces are excess and redundant.
I managed to display those stack traces using:
public static void displayStackStraceArray(StackTraceElement[] stackTraceElements) {
for (StackTraceElement elem : stackTraceElements) {
System.err.println("\t"+elem.toString());
}
}
You may check each stack trace entry for mention of your class file at the end of the line:
public static void displayStackStraceArray(StackTraceElement[] stackTraceElements) {
for (StackTraceElement elem : stackTraceElements) {
String line = elem.toString();
// assuming the file is called Search_Task.java:
if (line.matches(".*\\(Search_Task\\.java:\\d+\\)$")) {
System.err.println("\t"+elem.toString());
}
}
}
As JB Nizet notes in a comment, you should use your own specific package instead of starting it with android.
public static final String PACKAGE_ROOT = "org.example.application";
public static void displayStackStraceArray(StackTraceElement[] stackTraceElements) {
for (StackTraceElement elem : stackTraceElements) {
if (elem.getClassName().startsWith(PACKAGE_ROOT)) {
System.err.println("\t"+elem.toString());
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With