FileDocCategorySizeDatePackage
StackTraceElement.javaAPI DocAndroid 1.5 API7608Wed May 06 22:41:04 BST 2009java.lang

StackTraceElement

public final class StackTraceElement extends Object implements Serializable
A representation of a single stack frame. Arrays of {@code StackTraceElement} are stored in {@link Throwable} objects to represent the whole state of the call stack at the time a {@code Throwable} gets thrown.
see
Throwable#getStackTrace()
since
Android 1.0

Fields Summary
private static final long
serialVersionUID
private static final int
NATIVE_LINE_NUMBER
String
declaringClass
String
methodName
String
fileName
int
lineNumber
Constructors Summary
public StackTraceElement(String cls, String method, String file, int line)
Constructs a new {@code StackTraceElement} for a specified execution point.

param
cls the fully qualified name of the class where execution is at.
param
method the name of the method where execution is at.
param
file The name of the file where execution is at or {@code null}.
param
line the line of the file where execution is at, a negative number if unknown or {@code -2} if the execution is in a native method.
throws
NullPointerException if {@code cls} or {@code method} is {@code null}.
since
Android 1.0


                                                                                                                                                                                 
             
        super();
        if (cls == null || method == null) {
            throw new NullPointerException();
        }
        declaringClass = cls;
        methodName = method;
        fileName = file;
        lineNumber = line;
    
private StackTraceElement()

Private, nullary constructor for VM use only.

        super();
    
Methods Summary
public booleanequals(java.lang.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:
  • {@code obj} must be a stack trace element,
  • the method names of this stack trace element and of {@code obj} must not be {@code null},
  • the class, method and file names as well as the line number of this stack trace element and of {@code obj} must be equal.

param
obj the object to compare this instance with.
return
{@code true} if the specified object is equal to this {@code StackTraceElement}; {@code false} otherwise.
see
#hashCode
since
Android 1.0

        if (!(obj instanceof StackTraceElement)) {
            return false;
        }
        StackTraceElement castObj = (StackTraceElement) obj;

        /*
         * Unknown methods are never equal to anything (not strictly to spec,
         * but spec does not allow null method/class names)
         */
        if ((methodName == null) || (castObj.methodName == null)) {
            return false;
        }

        if (!getMethodName().equals(castObj.getMethodName())) {
            return false;
        }
        if (!getClassName().equals(castObj.getClassName())) {
            return false;
        }
        String localFileName = getFileName();
        if (localFileName == null) {
            if (castObj.getFileName() != null) {
                return false;
            }
        } else {
            if (!localFileName.equals(castObj.getFileName())) {
                return false;
            }
        }
        if (getLineNumber() != castObj.getLineNumber()) {
            return false;
        }

        return true;
    
public java.lang.StringgetClassName()
Returns the fully qualified name of the class belonging to this {@code StackTraceElement}.

return
the fully qualified type name of the class
since
Android 1.0

        return (declaringClass == null) ? "<unknown class>" : declaringClass;
    
public java.lang.StringgetFileName()
Returns the name of the Java source file containing class belonging to this {@code StackTraceElement}.

return
the name of the file, or {@code null} if this information is not available.
since
Android 1.0

        return fileName;
    
public intgetLineNumber()
Returns the line number in the source for the class belonging to this {@code StackTraceElement}.

return
the line number, or a negative number if this information is not available.
since
Android 1.0

        return lineNumber;
    
public java.lang.StringgetMethodName()
Returns the name of the method belonging to this {@code StackTraceElement}.

return
the name of the method, or "" if this information is not available.
since
Android 1.0

        return (methodName == null) ? "<unknown method>" : methodName;
    
public inthashCode()

        /*
         * Either both methodName and declaringClass are null, or neither are
         * null.
         */
        if (methodName == null) {
            // all unknown methods hash the same
            return 0;
        }
        // declaringClass never null if methodName is non-null
        return methodName.hashCode() ^ declaringClass.hashCode();
    
public booleanisNativeMethod()
Indicates if the method name returned by {@link #getMethodName()} is implemented as a native method.

return
{@code true} if the method in which this stack trace element is executing is a native method; {@code false} otherwise.
since
Android 1.0

        // BEGIN android-changed
        return lineNumber == NATIVE_LINE_NUMBER;
        // END android-changed
    
public java.lang.StringtoString()

        StringBuilder buf = new StringBuilder(80);

        buf.append(getClassName());
        buf.append('.");
        buf.append(getMethodName());

        if (isNativeMethod()) {
            buf.append("(Native Method)");
        } else {
            String fName = getFileName();

            if (fName == null) {
                buf.append("(Unknown Source)");
            } else {
                int lineNum = getLineNumber();

                buf.append('(");
                buf.append(fName);
                if (lineNum >= 0) {
                    buf.append(':");
                    buf.append(lineNum);
                }
                buf.append(')");
            }
        }
        return buf.toString();