Android stack trace

How can I get printStackTrace equivalent in android? I know that I can log an error by passing the tag name and String to the logging method, but that just gives me a nullpointer exception. If I call e.printStackTrace (), where is this data printed on?

+8
android
source share
4 answers

If you are using eclipse, make sure you have the LogCat window LogCat . You can find it under

Window-> Show View-> Other β†’ In Android β†’ LogCat

updated: 2014 July

OR, if you are using Android Studio, you can find it under

Menu window β†’ Show view β†’ Log file

LogCat is like a console in regular JAVA. Your e.printstacktrace() will also appear in LogCat.

+5
source share
 Log.e("mytag", "mymessage",ex); 
+17
source share

Data is still printed in DDMS logs with e.printStackTrace (); You can also use Log.e ("Tag", "Description", e); which will also print magazines. DDMS is located in android-sdk / tools / ddms, and the logs will appear in the bottom pane at startup.

+2
source share

First, if you have not already done so, you should wrap your code in a try-catch structure, for example, as follows:

 private String TAG = "MyMethodName"; // change this to anything that makes sense to you try { ... Log.d(TAG, "processed OK"); } catch (Exception except) { Log.e(TAG,"CRASH StackTrace: "+ Arrays.toString(except.getStackTrace())); } 

This pseudo code will show the full stack trace.

NEWBIE ALERT: Before publishing the application, be sure to β€œcomment” (using // ) this and all debugging functions that can be used to display the internal components of your code. Anyone who connects a device using your code with ADB enabled will be able to access LogCat (where Log publishes).

0
source share

All Articles