今天不知道什么原因,应用总是莫名奇妙崩溃,而且没有相应的堆栈信息可以打印,这个问题困扰了我很久,最后查找了一下,发现不止我自己遇到这种问题,加了下面这段代码,就可以顺利找出问题所在
try {
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
Log.e(TAG, "Uncaught Exception detected in thread {}" + t.getName() + e.getMessage());
for (StackTraceElement s : e.getStackTrace()) {
Log.e(TAG, s.toString());
}
}
});
} catch (SecurityException e) {
Log.e(TAG, "Could not set the Default Uncaught Exception Handler" + e.getLocalizedMessage());
}
http://stackoverflow.com/questions/11225209/thread-exiting-with-uncaught-exception-no-stack-trace