Use LogCat to Debug for Android

To use LogCat you need to import the Log library in the java code import android.util.Log;

Then, where you would normally print something, replace “System.out.println(“HERE”);” with:

Log.d(“LOGCAT”, “HERE”);

Now when you run your app on the emulator or a device it'll print out to logcat, which can be viewed right in Eclipse (might need to go to Tools and click LogCat or something similar) or in the terminal in the directory where the android sdk has been installed, in the <sdk>/platform-tools/ folder.

Run adb logcat from that directory location to view the logs.

This prints out a log of everything that's happening, so if it's on the phone there's probably going to be a lot of stuff going on continuously, which is why it's helpful to use good tags so you can just browse or search for "LOGCAT" and you'll find what you're looking for.

Using LogCat in NetBeans

The best way to debug in Android is to use LogCat.  I've yet to figure out an easy way to do this though -- using NetBeans -- but it can be done.  LogCat should be installed with your Android SDK and AVD (android virtual device) kits, however the problem is that NetBeans doesn't display logcat in a "console"-like format.  I was looking at this tonight and figured out how you can still get your LogCat printout -- it just prints straight to a text file and not in a nice built-in display window like Eclipse has.
1) First, you'll have to add the adb tools path the Windows global variable (if you're on a mac you'll have to google how to do this).  See
2) Then, whenever you run your app and it crashes (or anytime you want to debug), open the command prompt and enter:
adb logcat -v time > logcat.txt
This will create a file in the current folder with the current LogCat logs.  You'll have a lot of stuff in there so it's important that you've used LogCat properly in your code so that you know what to look for.  Run "start logcat.txt" to take a look.
3) To to use LogCat in your code you'll first need to import the Log library:
import android.util.Log;
Then, down where you would normally print something out, you'll replace "System.out.println("HERE");" with:
Log.d("LOGCAT", "HERE");
4) Now, run the logcat command again, then open the text file with the start command:
adb logcat -v time > logcat.txt
start logcat.txt
5) Now, use CTRL-F "LOGCAT" to look through all your LOGCAT debugging statements.
Also - If your app is crashing try searching for "E/AndroidRuntime"... this will take you to the information on what caused the error.
I know it's a little complicated, but it works!  And it'll let you debug crash errors too.  The problem with using toasts for debugging is that the app may crash before you ever reach the toast.  Which... ends up not really helping you at all.  So if you can bear the pain of these steps for your debugging, it should help out a lot!   And if you find a better way to use LogCat in NetBeans please let me know.  It would be awesome if they let you view the LogCat logs directly in NetBeans.  Man that would be sweet.  Good luck!
Let me know if you find any mistakes with the info above.