Student
Student

Reputation: 28345

Why Android doesn't print the stack trace?

Even explicitly writing e.printStackTrace() it doesn't print to the console, why?

Upvotes: 4

Views: 4959

Answers (4)

Bill the Lizard
Bill the Lizard

Reputation: 405745

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.)

Upvotes: 2

solgar
solgar

Reputation: 4691

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.

Upvotes: 1

Nicholas
Nicholas

Reputation: 7501

use Log.X() where X is the type of error console you want(Log.e, Log.v, Log.d, etc.)

Upvotes: 1

Pentium10
Pentium10

Reputation: 207902

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

Or use the ddms command tool to read logcat.

alt text

Upvotes: 7

Related Questions