Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android中获得完整的堆栈跟踪?_Android_Google Analytics - Fatal编程技术网

如何在android中获得完整的堆栈跟踪?

如何在android中获得完整的堆栈跟踪?,android,google-analytics,Android,Google Analytics,我正在使用以下代码 public static String getCombinedStackTrace(Throwable aThrowable) { final StringBuilder result = new StringBuilder(); result.append(aThrowable.toString()); result.append(','); String oneEleme

我正在使用以下代码

public static String getCombinedStackTrace(Throwable aThrowable) {

            final StringBuilder result = new StringBuilder();
            result.append(aThrowable.toString());
            result.append(',');

            String oneElement;

            for (StackTraceElement element : aThrowable.getStackTrace() ) {
                oneElement = element.toString();
                result.append( oneElement );
                result.append( ",");
            }
return result.toString();
}
它返回“原因:”之前的堆栈跟踪,但我想在“原因:”之后也返回堆栈跟踪。 提前谢谢

Caused by: java.sql.BatchUpdateException: failed batch
    at org.hsqldb.jdbc.jdbcStatement.executeBatch(jdbcStatement.java:1102)
    at org.hsqldb.jdbc.jdbcPreparedStatement.executeBatch(jdbcPreparedStatement.java:514)
    at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
    at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)

我无法获取“由以下原因引起的:”行

如果您的垃圾有原因,可以通过调用

Throwable cause = aThrowable.getCause();
然后你可以递归地打电话

getCombinedStackTrace(cause);
并浓缩结果以获得完整的堆栈跟踪。

您可以使用以下代码:

import java.io.PrintWriter;
import java.io.StringWriter;

 Writer result = new StringWriter();
            PrintWriter printWriter = new PrintWriter(result);
            e.printStackTrace(printWriter);
            //String stacktrace = result.toString();
            //Report += stacktrace;
            printWriter.append( "\n"
                    + "Cause : \n"
                    + "======= \n");

            // If the exception was thrown in a background thread inside
            // AsyncTask, then the actual exception can be found with getCause
            Throwable cause = e.getCause();
            while (cause != null) {
                cause.printStackTrace(printWriter);
                cause = cause.getCause();
            }

            String trace = result.toString(); // here is the result!
            printWriter.close();

谢谢。同样的问题,老板。它显示到“at dalvik.system.NativeStart.main(本机方法)”,但是“起因”没有得到解决