[GUIDE] Debugging apps

Search This thread

nilaydani

Member
Jan 3, 2014
40
37
35
ahmedabad
Thanks

This is really helpful ...
I am sharing one trick who frequently face AVD issue..
Just delete avd folder inside ur ".android" folder which can be found on c:/Users/UserName ...
 
  • Like
Reactions: nikwen

iamareebjamal

Senior Member
Aug 7, 2012
3,703
5,127
27
Batcave
www.facebook.com
This is probably the best place to ask my question, so here :

I have a ROM control app which has a wallpaper option, which works flawlessly on Gingerbread but gives a NullPointerException in ICS+

Here's the logcat

Code:
D/AndroidRuntime(19049): Shutting down VM
E/AndroidRuntime(19049): FATAL EXCEPTION: main
E/AndroidRuntime(19049): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cosmic.mods/com.cosmic.mods.Wallpaper}: java.lang.NullPointerException
E/AndroidRuntime(19049): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
E/AndroidRuntime(19049): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
E/AndroidRuntime(19049): 	at android.app.ActivityThread.access$700(ActivityThread.java:159)
E/AndroidRuntime(19049): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
E/AndroidRuntime(19049): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(19049): 	at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(19049): 	at android.app.ActivityThread.main(ActivityThread.java:5419)
E/AndroidRuntime(19049): 	at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(19049): 	at java.lang.reflect.Method.invoke(Method.java:525)
E/AndroidRuntime(19049): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
E/AndroidRuntime(19049): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
E/AndroidRuntime(19049): 	at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:126)
E/AndroidRuntime(19049): 	at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(19049): Caused by: java.lang.NullPointerException
E/AndroidRuntime(19049): 	at com.cosmic.mods.Wallpaper.onCreate(Wallpaper.java:58)
E/AndroidRuntime(19049): 	at android.app.Activity.performCreate(Activity.java:5372)
E/AndroidRuntime(19049): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
E/AndroidRuntime(19049): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
E/AndroidRuntime(19049): 	... 12 more

Here's the code

https://github.com/iamareebjamal/cosmic_hub/blob/master/src/com/cosmic/mods/Wallpaper.java

The line 58, where it's showing the error is

Code:
getSupportActionBar(). setDisplayHomeAsUpEnabled(true);

I understand that it may not be exact line throwing the error.

IDK what may be the problem. Stranger thing is that the same code for wallpapers work in my other app(icon pack) fine on any Android version
 

ziondreamt

Member
Aug 8, 2013
18
4
Pensacola
My gosh I've been wrapping the nasty ones in try/catch and shrinking it till i find the culprit, I knew about the debugger for eclipse but i thought it took more to setup. thank you sir.
 
  • Like
Reactions: nikwen

nikwen

Senior Member
Feb 1, 2013
3,142
1,597
Berlin, Germany
www.nikwen.de
My gosh I've been wrapping the nasty ones in try/catch and shrinking it till i find the culprit, I knew about the debugger for eclipse but i thought it took more to setup. thank you sir.

You're welcome. ;)

This is probably the best place to ask my question, so here :

I have a ROM control app which has a wallpaper option, which works flawlessly on Gingerbread but gives a NullPointerException in ICS+

Here's the logcat

Code:
D/AndroidRuntime(19049): Shutting down VM
E/AndroidRuntime(19049): FATAL EXCEPTION: main
E/AndroidRuntime(19049): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cosmic.mods/com.cosmic.mods.Wallpaper}: java.lang.NullPointerException
E/AndroidRuntime(19049): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
E/AndroidRuntime(19049): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
E/AndroidRuntime(19049): 	at android.app.ActivityThread.access$700(ActivityThread.java:159)
E/AndroidRuntime(19049): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
E/AndroidRuntime(19049): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(19049): 	at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(19049): 	at android.app.ActivityThread.main(ActivityThread.java:5419)
E/AndroidRuntime(19049): 	at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(19049): 	at java.lang.reflect.Method.invoke(Method.java:525)
E/AndroidRuntime(19049): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
E/AndroidRuntime(19049): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
E/AndroidRuntime(19049): 	at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:126)
E/AndroidRuntime(19049): 	at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(19049): Caused by: java.lang.NullPointerException
E/AndroidRuntime(19049): 	at com.cosmic.mods.Wallpaper.onCreate(Wallpaper.java:58)
E/AndroidRuntime(19049): 	at android.app.Activity.performCreate(Activity.java:5372)
E/AndroidRuntime(19049): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
E/AndroidRuntime(19049): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
E/AndroidRuntime(19049): 	... 12 more

Here's the code

https://github.com/iamareebjamal/cosmic_hub/blob/master/src/com/cosmic/mods/Wallpaper.java

The line 58, where it's showing the error is

Code:
getSupportActionBar(). setDisplayHomeAsUpEnabled(true);

I understand that it may not be exact line throwing the error.

IDK what may be the problem. Stranger thing is that the same code for wallpapers work in my other app(icon pack) fine on any Android version

I guess that this one should solve your problem: http://stackoverflow.com/a/10124627 ;)

Btw, it is line 58 which throws the Exception. That message is always right. The reason for the error might be in another line but the program crahes in line 58.
 

m4RinKo2

Senior Member
Oct 5, 2012
947
512
24
DSP Manager

Hi! First, awesome thread, its very helpful! I am trying to build dsp manager from source. I am using the code from cyanogenmod github (gingerbread branch). https://github.com/CyanogenMod/android_packages_apps_DSPManager/tree/gingerbread I didnt do any modifications to the code. And when I want to change equalizer settings it fcs.
Here is the log:
Code:
01-12 18:19:26.945: E/AndroidRuntime(16249): FATAL EXCEPTION: main
01-12 18:19:26.945: E/AndroidRuntime(16249): java.lang.RuntimeException: Error receiving broadcast Intent { act=com.bel.android.dspmanager.UPDATE } in com.bel.android.dspmanager.HeadsetService$2@4050dbb0
01-12 18:19:26.945: E/AndroidRuntime(16249): 	at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:722)
01-12 18:19:26.945: E/AndroidRuntime(16249): 	at android.os.Handler.handleCallback(Handler.java:587)
01-12 18:19:26.945: E/AndroidRuntime(16249): 	at android.os.Handler.dispatchMessage(Handler.java:92)
01-12 18:19:26.945: E/AndroidRuntime(16249): 	at android.os.Looper.loop(Looper.java:130)
01-12 18:19:26.945: E/AndroidRuntime(16249): 	at android.app.ActivityThread.main(ActivityThread.java:3687)
01-12 18:19:26.945: E/AndroidRuntime(16249): 	at java.lang.reflect.Method.invokeNative(Native Method)
01-12 18:19:26.945: E/AndroidRuntime(16249): 	at java.lang.reflect.Method.invoke(Method.java:507)
01-12 18:19:26.945: E/AndroidRuntime(16249): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
01-12 18:19:26.945: E/AndroidRuntime(16249): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
01-12 18:19:26.945: E/AndroidRuntime(16249): 	at dalvik.system.NativeStart.main(Native Method)
01-12 18:19:26.945: E/AndroidRuntime(16249): Caused by: java.lang.IllegalArgumentException: AudioEffect: bad parameter value
01-12 18:19:26.945: E/AndroidRuntime(16249): 	at android.media.audiofx.AudioEffect.checkStatus(AudioEffect.java:1179)
01-12 18:19:26.945: E/AndroidRuntime(16249): 	at android.media.audiofx.Equalizer.setBandLevel(Equalizer.java:229)
01-12 18:19:26.945: E/AndroidRuntime(16249): 	at com.bel.android.dspmanager.HeadsetService.updateDsp(HeadsetService.java:220)
01-12 18:19:26.945: E/AndroidRuntime(16249): 	at com.bel.android.dspmanager.HeadsetService$2.onReceive(HeadsetService.java:100)
01-12 18:19:26.945: E/AndroidRuntime(16249): 	at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:709)
01-12 18:19:26.945: E/AndroidRuntime(16249): 	... 9 more
TIA!
 

m4RinKo2

Senior Member
Oct 5, 2012
947
512
24
Hi! First, awesome thread, its very helpful! I am trying to build dsp manager from source. I am using the code from cyanogenmod github (gingerbread branch). https://github.com/CyanogenMod/android_packages_apps_DSPManager/tree/gingerbread I didnt do any modifications to the code. And when I want to change equalizer settings it fcs.
Here is the log:
Code:
01-12 18:19:26.945: E/AndroidRuntime(16249): FATAL EXCEPTION: main
01-12 18:19:26.945: E/AndroidRuntime(16249): java.lang.RuntimeException: Error receiving broadcast Intent { act=com.bel.android.dspmanager.UPDATE } in com.bel.android.dspmanager.HeadsetService$2@4050dbb0
01-12 18:19:26.945: E/AndroidRuntime(16249): 	at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:722)
01-12 18:19:26.945: E/AndroidRuntime(16249): 	at android.os.Handler.handleCallback(Handler.java:587)
01-12 18:19:26.945: E/AndroidRuntime(16249): 	at android.os.Handler.dispatchMessage(Handler.java:92)
01-12 18:19:26.945: E/AndroidRuntime(16249): 	at android.os.Looper.loop(Looper.java:130)
01-12 18:19:26.945: E/AndroidRuntime(16249): 	at android.app.ActivityThread.main(ActivityThread.java:3687)
01-12 18:19:26.945: E/AndroidRuntime(16249): 	at java.lang.reflect.Method.invokeNative(Native Method)
01-12 18:19:26.945: E/AndroidRuntime(16249): 	at java.lang.reflect.Method.invoke(Method.java:507)
01-12 18:19:26.945: E/AndroidRuntime(16249): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
01-12 18:19:26.945: E/AndroidRuntime(16249): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
01-12 18:19:26.945: E/AndroidRuntime(16249): 	at dalvik.system.NativeStart.main(Native Method)
01-12 18:19:26.945: E/AndroidRuntime(16249): Caused by: java.lang.IllegalArgumentException: AudioEffect: bad parameter value
01-12 18:19:26.945: E/AndroidRuntime(16249): 	at android.media.audiofx.AudioEffect.checkStatus(AudioEffect.java:1179)
01-12 18:19:26.945: E/AndroidRuntime(16249): 	at android.media.audiofx.Equalizer.setBandLevel(Equalizer.java:229)
01-12 18:19:26.945: E/AndroidRuntime(16249): 	at com.bel.android.dspmanager.HeadsetService.updateDsp(HeadsetService.java:220)
01-12 18:19:26.945: E/AndroidRuntime(16249): 	at com.bel.android.dspmanager.HeadsetService$2.onReceive(HeadsetService.java:100)
01-12 18:19:26.945: E/AndroidRuntime(16249): 	at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:709)
01-12 18:19:26.945: E/AndroidRuntime(16249): 	... 9 more
TIA!

Please?
 

congminh1709

Senior Member
Dec 7, 2011
102
11
I just want to add more 2 methods for debugging: write log to file or set debug to your packages process at ddms tab of Ecllipse. These methods will be useful if you work with JNI or an app doesn't support to run from launcher.

Sent from my GT-N7100 using Tapatalk
 
Last edited:
  • Like
Reactions: nikwen

eng.ahmed.android

Senior Member
Dec 11, 2013
67
23
AVDs

I guess that nearly every developer for Android knows them and uses them: AVDs or emulators

They are great for testing your apps on other screen sizes or platform versions.

Before releasing your app, test them on different screen sizes and (most important) on different versions of Android. Some methods are just available on new API versions and crash on old versions. Another thing to mention: If your layout is designed for large screens, it might look bad on small ones. In the same manner phone layout often look ugly on a tablet.

Creating AVDs: Official documentation
ROOTING an AVD: Guide by Androguide.fr

Thanks for your efforts :)

About emulators, I have used to use android emulator which comes with android sdk but i recently see some people use a new emulator which called genymotion. Could you please show us what is the difference between it and normal emulator?? And do you encourage me to use it instead of formal emulator ??

Thanks in advance :)
 

dewankpant

Senior Member
Aug 18, 2014
68
15
The question might be a bit off topic, i am working on a root app development but i am pretty confused that how should i get the busbox commands to run on button press, i have given the path and everything but how am i supposed to create a busbox file in data/data/package/files.
This part is confusing me I am not able to create that file, should i keep it in res while creating the app ? And also one last question, from where can i get that busbox file with all its command. Please help, I'm sorry if this is the wrong forum I'm new to posting questions and also to app development .
 

nikwen

Senior Member
Feb 1, 2013
3,142
1,597
Berlin, Germany
www.nikwen.de
The question might be a bit off topic, i am working on a root app development but i am pretty confused that how should i get the busbox commands to run on button press, i have given the path and everything but how am i supposed to create a busbox file in data/data/package/files.
This part is confusing me I am not able to create that file, should i keep it in res while creating the app ? And also one last question, from where can i get that busbox file with all its command. Please help, I'm sorry if this is the wrong forum I'm new to posting questions and also to app development .

I'd suggest creating a separate thread for that question in the Java for Android App Development forum. That's better than posting your question in already existing threads that have a different topic. ;)
 

Top Liked Posts

  • There are no posts matching your filters.
  • 24
    Debugging apps

    This is my multi-post guide on debugging apps.

    Android provides its own ways of debugging:

    Logcat

    The most important aspect when we talk about debugging. Whenever your app crashes, you can find the reason for that in the logs (as long as you install it from your IDE).

    However, we can also use it for other ways of debugging. It can help to understand how the app acts and why it does so.

    Toasts

    Toasts are these small pop-ups you can see in many apps. You can use them for debugging as well.

    Debugger in Eclipse or Android Studio

    Eclipse and Android Studio have their own debuggers. You can execute the source code step by step and see all variable values during that.

    AVDs

    If a user reports that the layout does not look great on his device, you can check it using an AVD, often refered to as an emulator. It can help to understand how the app will look on other devices.

    Using Google and posting on XDA

    Google can help you very much with your problem. If you still cannot figure out what the reasons for your problem are, you can profit by the XDA community power. However, we need some information in order to help you.


    This was featured on the XDA portal on June 29, 2013. :D
    22
    Logcat

    As I have already stated, logcats are the most important aspect of debugging on Android.

    You can use them to get error messages when your app crashed or to print your own debugging information.

    Understand error messages

    This is one example of an error message you can get:

    Code:
    06-15 12:45:02.205      805-805/?                              E/AndroidRuntime: FATAL EXCEPTION: main
            java.lang.RuntimeException: Unable to start activity ComponentInfo{de.nikwen.myapplication/de.nikwen.myapplication.MainActivity}: java.lang.NullPointerException
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
            at android.app.ActivityThread.access$600(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5041)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
            at dalvik.system.NativeStart.main(Native Method)
            Caused by: java.lang.NullPointerException
            at de.nikwen.myapplication.MainActivity.doSomething(MainActivity.java:21)
            at de.nikwen.myapplication.MainActivity.onCreate(MainActivity.java:17)
            at android.app.Activity.performCreate(Activity.java:5104)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
            ... 11 more

    The code producing the error:

    Code:
    package de.nikwen.myapplication;
    
    import android.os.Bundle;
    import android.app.Activity;
    import android.view.Menu;
    import android.widget.Button;
    
    public class MainActivity extends Activity {
    
        Button myButton;
        
        @[B][/B]Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            
            doSomething();
        }
    
        private void doSomething() {
            myButton.setText("Crashing here");
        }
        
    }

    Now we are going to analyse the error.

    The second line is the most important one. It tells you which kind of error ocurred. In this case it is a NullPointerException (NPE).

    Code:
    java.lang.RuntimeException: Unable to start activity ComponentInfo{de.nikwen.myapplication/de.nikwen.myapplication.MainActivity}: java.lang.[COLOR="Red"]NullPointerException[/COLOR]

    The first thing to do now is searching for this type of error. When does it occur?

    You come up with something like this:

    Thrown when an application attempts to use null in a case where an object is required. These include:

    • Calling the instance method of a null object.
    (Source: http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/NullPointerException.html)

    Now you know what kind of Exception was thrown. You can get a lot of other useful information from the logcat:

    Usually, you get some more information about the error. There should be an explanation why the Exception was thrown:

    Code:
    java.lang.RuntimeException: [COLOR="Red"]Unable to start activity[/COLOR] ComponentInfo{de.nikwen.myapplication/de.nikwen.myapplication.MainActivity}: java.lang.NullPointerException

    It also prints the stacktrace. The stacktrace contains all methods which have been invoked, the last one on the top.

    In this case one exception caused another one. In most cases, the one which caused the other one is the one which is interesting for you.

    Code:
    Caused by: java.lang.NullPointerException

    In this case the one which was thrown first is a NPE as well.

    Let us have a closer look at the stacktrace:

    Code:
    [COLOR="Red"]at de.nikwen.myapplication.MainActivity.doSomething(MainActivity.java:21)
    at de.nikwen.myapplication.MainActivity.onCreate(MainActivity.java:17)[/COLOR]
    at android.app.Activity.performCreate(Activity.java:5104)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)

    The ones which are important for you usually are the ones with your package name (the red ones).
    At the end of the line it tells you in which file and in which line the error occured.

    Code:
    at de.nikwen.myapplication.MainActivity.onCreate[COLOR="Red"](MainActivity.java:17)[/COLOR]

    Here it is just the part of the code where the other method is called. So we look at the other one. (This most often happens when there are two of your methods. For that reason have a look at the upper one first.)

    Code:
    at de.nikwen.myapplication.MainActivity.doSomething[COLOR="Red"](MainActivity.java:21)[/COLOR]

    It tells us MainActivity.java, line 21.

    That is the line:

    Code:
    myButton.setText("Crashing here");

    Remember, we got a NullPointerException. The only variable that can get null in that line is myButton. In fact we initialise it nowhere.

    So this is our new onCreate method:

    Code:
    @[B][/B]Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
            
        myButton = (Button) findViewById(R.id.my_button);
    
        doSomething();
    }

    We solved the error. :victory:
    13
    Posting on XDA

    This should be your last option. Try everything you can before posting here. Though posting your problem on XDA is nothing you should be ashamed of.

    However, please follow these steps to ensure that we are able to help you properly:

    1. Give us your code.
      Do not worry. You do not have to publish all of your code but the relevant parts. That means the class which causes the Exception. If you can exclude some methods to be the reason for the Exception, you do not need to post them. But do this only if you are sure that they are not important for us.
    2. Post a logcat.
      As you can see in post #2, logcats are the most important information on the bug and the reasons why it crashes.
    3. Describe the problem.
      Tell us when the code crashes. That might be that it crashes when you change the screen orientation, press the menu or back key or when a particular method is invoked. Many of us do not execute your code but just look at it in the browser. Hence we need to know when the code crashes. ;)

    Liked this tutorial?

    Check out my interactive tutorial on how to use the command line.
    12
    Debugger in Eclipse

    The debugger of Eclipse is a very productive tool. It allows you to see the values of the variables in real time. Additionally, you will be able to see and control exactly what your app is doing while it is running. :)

    If we want to start our app in debug mode, we have to run it using the debug button.

    picture.php


    To set or delete breakpoints we can right-click on the space left to the source code and select "Toggle Breakpoint". You will notice a blue dot next to the line. When the app is running, it will stop executing the code at the position of the breakpoint. The line with the breakpoint will not be executed.

    picture.php


    picture.php


    When you run the app now, it will show a dialog which says that it is waiting for the debugger to attach.

    picture.php


    You will also see a pop-up asking you to launch the debug perspective. Hit "Yes".

    picture.php


    picture.php


    The code of your app will be executed, but it will stop before executing the line with your breakpoint. The current line which is not executed yet will be marked green.

    picture.php


    Now you can decide what should be done next. The proper controls can be found in the debug perspective we opened before.

    picture.php


    The one on the left will run the code until the next breakpoint will be reached. This will be the next thing we see if we define another breakpoint and press the "Resume" button:

    picture.php


    The red button will disconnect the debugger. If you do this, your app will go on running as if no debugger had ever been attached.

    Let us talk about the other buttons. The left one will make your program execute the current line and if it is a method, it will step into this method and you will be able to debug the other method step by step, too. It is called "Step into". The debugger will not be able to step into methods which are not defined by you or any library you added to your project.
    If you want the debugger to execute the next line but (if the line is a method) not to step into the method, use the second button called "Step over". It will directly go to the next line.
    If you are in a method and want to step out of it, use the third button. That means that it will leave the current method. Note that it will still run all code of the current method. Its name is "Step return".

    In the picture above the buttons would cause this:
    • The "Step into" button will continue with the first line of the doSomething() method.
    • The "Step over" button will run the doSomething() and pause afterwards.
    • The "Step return" method will run the onCreate() method until its end and will pause then.

    Now let us see how we can get the value of variables.

    All variables used in the current method will be shown in the debugger view.

    picture.php


    If there is an array, you can view its childs by clicking on the arrow next to it.

    picture.php


    You can also view the fields of an object by clicking on the arrow.

    picture.php


    If you hover of a variable in the code view, you will see its value, too.

    picture.php


    I think that now you see why I call the debugger a productive tool. ;)
    And if I had shown you everything you can do with it, it would have been to long to post it on XDA. The ones I showed you are just the basic functions of the debugger. :)
    10
    Logcat - part II

    Your own debug messages

    We can also output our own debugging information that way:

    Code:
    Log.d("myTag", "myMessage");
    or
    Code:
    Log.e("myTag", "myErrorMessage");

    Error messages (produced with Log.e) are shown in red.

    The tag can be used for filtering.

    It can help us to check specific values when it does not return the right output:

    Code:
    Log.d("start", "hey");
    
    String[] myStringArray = new String[] {"Hello world", "Debugging is fun (normally not ;))", "XDA is great!!!"};
    
    String all = "Words: ";
    
    for (String s: myStringArray) {
        Log.d("String s", s);
        all = all + s + ", ";
        Log.d("new all", all);
    }
            
    Log.d("status", "done");

    The output:

    Code:
    06-15 13:15:03.014    1347-1347/de.nikwen.myapplication        D/start: hey
    06-15 13:15:03.014    1347-1347/de.nikwen.myapplication        D/String s: Hello world
    06-15 13:15:03.014    1347-1347/de.nikwen.myapplication        D/new all: Words: Hello world,
    06-15 13:15:03.014    1347-1347/de.nikwen.myapplication        D/String s: Debugging is fun (normally not ;))
    06-15 13:15:03.014    1347-1347/de.nikwen.myapplication        D/new all: Words: Hello world, Debugging is fun (normally not ;)),
    06-15 13:15:03.014    1347-1347/de.nikwen.myapplication        D/String s: XDA is great!!!
    06-15 13:15:03.014    1347-1347/de.nikwen.myapplication        D/new all: Words: Hello world, Debugging is fun (normally not ;)), XDA is great!!!,
    06-15 13:15:03.014    1347-1347/de.nikwen.myapplication        D/status: done

    You can also use the log if one of your methods does not finish:

    Code:
    for (int i = 0; i < 20; i--) {
        //do something
        
        Log.d("i", String.valueOf(i));
    }
    
    Log.d("status", "1");
    
    myButton.setText("New text");
    
    Log.d("status", "2");
    
    Log.d("status", "done");

    You can figure out the reason for logical errors by printing the required information to the logs.

    If there are Exceptions you want to handle but you still want the error standard Java error message discussed in the previous post, use the printStackTrace() method of the class Exception:

    Code:
    try {
        Thread.sleep(5000);
    } catch(Exception e) {
        e.printStackTrace();
        
        //do something here
    }