简体   繁体   中英

Why Android doesn't print the stack trace?

即使显式写e.printStackTrace()它也不会打印到控制台,为什么?

Checkout Logcat in DDMS perspective it should be there not in the Console tab.

Or use the ddms command tool to read logcat.

替代文字

printStackTrace() doesn't print to the console, it prints to the standard error stream. If you want to print to the screen, set your display text to e.getMessage() or e.getStackTrace() . (Although I do recommend learning to debug with logcat instead.)

You cannot print to console on Android. You have to use Android Log class. When I have an exception and I want to print it I'm using:

for (StackTraceElement element : exception.getStackTrace())
    Log.e("my_tag", element.toString());

or you can try

String stackTrace = Log.getStackTraceString(throwable);

And after that you can print it to Android Log.

使用Log.X(),其中X是您想要的错误控制台的类型(Log.e,Log.v,Log.d等)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM