Skip to content

Most visited

Recently visited

navigation
Added in API level 1

StackTraceElement

public final class StackTraceElement
extends Object implements Serializable

java.lang.Object
   ↳ java.lang.StackTraceElement


A representation of a single stack frame. Arrays of StackTraceElement are stored in Throwable objects to represent the whole state of the call stack at the time a Throwable gets thrown.

See also:

Summary

Public constructors

StackTraceElement(String cls, String method, String file, int line)

Constructs a new StackTraceElement for a specified execution point.

Public methods

boolean equals(Object obj)

Compares this instance with the specified object and indicates if they are equal.

String getClassName()

Returns the fully qualified name of the class belonging to this StackTraceElement.

String getFileName()

Returns the name of the Java source file containing class belonging to this StackTraceElement.

int getLineNumber()

Returns the line number in the source for the class belonging to this StackTraceElement.

String getMethodName()

Returns the name of the method belonging to this StackTraceElement.

int hashCode()

Returns an integer hash code for this object.

boolean isNativeMethod()

Indicates if the method name returned by getMethodName() is implemented as a native method.

String toString()

Returns a string containing a concise, human-readable description of this object.

Inherited methods

From class java.lang.Object

Public constructors

StackTraceElement

Added in API level 1
StackTraceElement (String cls, 
                String method, 
                String file, 
                int line)

Constructs a new StackTraceElement for a specified execution point.

Parameters
cls String: the fully qualified name of the class where execution is at.
method String: the name of the method where execution is at.
file String: The name of the file where execution is at or null.
line int: the line of the file where execution is at, a negative number if unknown or -2 if the execution is in a native method.
Throws
NullPointerException if cls or method is null.

Public methods

equals

Added in API level 1
boolean equals (Object obj)

Compares this instance with the specified object and indicates if they are equal. In order to be equal, the following conditions must be fulfilled:

  • obj must be a stack trace element,
  • the method names of this stack trace element and of obj must not be null,
  • the class, method and file names as well as the line number of this stack trace element and of obj must be equal.

Parameters
obj Object: the object to compare this instance with.
Returns
boolean true if the specified object is equal to this StackTraceElement; false otherwise.

See also:

getClassName

Added in API level 1
String getClassName ()

Returns the fully qualified name of the class belonging to this StackTraceElement.

Returns
String the fully qualified type name of the class

getFileName

Added in API level 1
String getFileName ()

Returns the name of the Java source file containing class belonging to this StackTraceElement.

Returns
String the name of the file, or null if this information is not available.

getLineNumber

Added in API level 1
int getLineNumber ()

Returns the line number in the source for the class belonging to this StackTraceElement.

Returns
int the line number, or a negative number if this information is not available.

getMethodName

Added in API level 1
String getMethodName ()

Returns the name of the method belonging to this StackTraceElement.

Returns
String the name of the method, or "" if this information is not available.

hashCode

Added in API level 1
int hashCode ()

Returns an integer hash code for this object. By contract, any two objects for which equals(Object) returns true must return the same hash code value. This means that subclasses of Object usually override both methods or neither method.

Note that hash values must not change over time unless information used in equals comparisons also changes.

See Writing a correct hashCode method if you intend implementing your own hashCode method.

Returns
int this object's hash code.

isNativeMethod

Added in API level 1
boolean isNativeMethod ()

Indicates if the method name returned by getMethodName() is implemented as a native method.

Returns
boolean true if the method in which this stack trace element is executing is a native method; false otherwise.

toString

Added in API level 1
String toString ()

Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:

   getClass().getName() + '@' + Integer.toHexString(hashCode())

See Writing a useful toString method if you intend implementing your own toString method.

Returns
String a printable representation of this object.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.