What is the best way to debug an android application? Every once in a while the application crashes, an it says application has stopped unexpectedly, it never says why it crashes, or where in my code, what's the bet way to find the reason for crashes, and exceptions?
If you're using ADB just launch your app in debugging mode to gain a possibility to watch variables/expressions at runtime. You also can see the stacktrace in a Logcat window of your IDE if your app crashes.
there are several ways to do that, activate the LogCat and you will see there detailed info about what happens with your App.
or you will implement an error Handling sending the Exception info to a Toast
try {
...
your code
...
} catch (IOException e) {
Toast.makeText(getApplicationContext(), "Exception Info " + e.getCause()),Toast.LENGTH_LONG).show();
e.printStackTrace();
}
updated
Use the Android's Log class, and logcat, for example:
Log.d( "Your app name", "The value of x is: " + x );
And in logging output you'll get something like:
D/Your app name( 1001): The value of x is: 96
You can get logging output from command line by running: "adb logcat", or using Dalvik debug monitor (ddms in the tools directory of Android SDK)
Using Log is superior to using Toasts since Toasts are gone quite quickly, and logcat will show you a lot of information upon application crash (like filename and line number which caused unhandled exception)