yashsingh1/xdaforums huggingface dataset:
[Java for Android App Development] nikwen:
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.

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.

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

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

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.

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

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:

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.

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

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

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

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. :)
[Java for Android App Development] nikwen:
Debugger in Android Studio

The debugger of Android Studio is a very powerful tool which allows you to see the values of the variables while your app is running on the emulator or a real device. Additionally, you will be able to see and control exactly what it is doing in real time. :)

In order to debug an app we need to start it using the debug button.

Then we can define or delete breakpoints by clicking on the space left to the source code. A red dot will appear there. When running the app, it will stop executing the code at the position of the breakpoint. The line with the breakpoint will not be executed.

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

The debug view will be opened automatically.

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

Now you can control how your app should continue. The proper controls can be found in the debug view.

The one on the left will run the code until the next brekpoint will be reached. It is called "Resume program execution". The other four buttons are for smaller steps. This will be the next thing we see if we define another breakpoint and press the "Resume program execution" button:

Let us talk about the other four buttons. The left one will make your program execute the current line and go to the next line. It is called "Step over". If you do this, it will not step into other methods and debug them.

If you want the debugger to step into the method, use the second button 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 are in a method and want to step out of it, use the fourth 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 out" (Surprise :laugh:).

In the picture above the buttons would cause this:

The "Step over" button will run the doSomething() and pause afterwards.

The "Step into" button will continue with the first line of the doSomething() method.

The "Step out" method will run the onCreate() method until its end and will pause then.

Now we talk about getting variable values.

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

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

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

To see a certain value you can also hover above the variable in your code.

After that you see that the debugger is a very powerful tool. :)

And this is just the beginning. You can do even more complex actions with it. :)
[Java for Android App Development] nikwen:
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
[Java for Android App Development] nikwen:
Using Google

Google or any other search engine is great help when you debug your app. Nearly every error which occurs for you has already been experienced by others.

If you want to find out why your app crashes, search for this:

If it is no Android specific Exception (e.g. a NumberFormatException when using Integer.parseInt("27")), replace "Android" by "Java".

If no method which is written by you is causing the crash, use keywords like these:

Example for these could be:

Often it is the best way to search for the message you find in the logs, e.g.
[Java for Android App Development] nikwen:
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:

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.

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.

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.
[Java for Android App Development] matt95:
very very useful :D thanks
[Java for Android App Development] nikwen:
You are welcome. :)

I am glad that you like it. :)

Btw, I will update it soon. ;)
[Java for Android App Development] nikwen:
Updated the guide:

Post #8

Post #9
[Java for Android App Development] FlyLikeAGS3:
This is very helpful! When I was reading this in my book it was a little confusing but now I get it.
[Java for Android App Development] nikwen:
Posted the guide for the debugger of Android Studio. :)

Post #6
[Java for Android App Development] nikwen:
Added the Eclipse debugging tutorial. :)

Now I am done. :D

Post #5
[Java for Android App Development] Zatta:
I vote for another sticky by Nikwen!
[Java for Android App Development] nikwen:
Thanks. :)

If it is a sticky, people will see it. If not, nobody will see it due to the number of new posts every day.

([MENTION=2484146]mark manning[/MENTION])
[Java for Android App Development] mark manning:
I'll look at it later on when I get a sec ;)
[Java for Android App Development] LuigiBull23:
Great guide!
[Java for Android App Development] mark manning:
Thread is now stickied, good job made :)
[Java for Android App Development] nikwen:
Thank you VERY much. :good:
[Java for Android App Development] nikwen:
Big thanks to the portal team for featuring this. :)
[Java for Android App Development] majdinj:
Excellent job bro,, a very useful thread,,, keep it up
[Java for Android App Development] hidroela:
thanks a lot for the tutorial.

i got a request.

would you be considering add to the eclipse section how to attach sources to the debugger.

i have always problem with it.since a dont know how to do it.

bellow is and example of what i am talking about.

best regards

HP :good:
[Java for Android App Development] Adam77Root:
Just read this on the portal (http://www.xda-developers.com/android/guide-to-help-debug-your-apps/). Nice guide. You could add some hints (or just a link) about Android Device Monitor (http://developer.android.com/tools/help/monitor.html) with DDMS (http://developer.android.com/tools/debugging/ddms.html).
[Java for Android App Development] nikwen:
Yeah, that is what I described here:

The debugger is not able to debug any class you did not write.

Just use the "Step over" button for those methods. ;)
[Java for Android App Development] nikwen:
Thanks for the suggestion. I will think about it. ;)
[Java for Android App Development] benkxda:
Hey nikwen, you did it again. It's a "hattrick" now ;)

Again you are on the portal with your Guide to Help Debug Your Apps. Very good. Your contribute is really very good, or should I say recognizable? ;)
[Java for Android App Development] nikwen:
Hey, Thanks. :)
[Java for Android App Development] ahbsa:
thanks

heii...this is really helpfull.....

thanks man...:good::good::good:
[Java for Android App Development] nikwen:
Thanks. :)

Knowing how to solve your problems yourself is great. :good:
[Java for Android App Development] cycad:
Informative screenshots, well done and thank you.
[Java for Android App Development] a9entropy:
THanks buddy. Nice guide.
[Java for Android App Development] nikwen:
Welcome. And thanks for the nice words. :)
[Java for Android App Development] WittyPotato:
Very helpful indeed!
[Java for Android App Development] nilaydani:
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 ...
[Java for Android App Development] nikwen:
Thanks to both of you. :)
[Java for Android App Development] iamareebjamal:
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

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

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
[Java for Android App Development] ziondreamt:
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.
[Java for Android App Development] nikwen:
You're welcome. ;)

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.
[Java for Android App Development] m4RinKo2:
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:

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!
[Java for Android App Development] m4RinKo2:
Please?
[Java for Android App Development] nikwen:
Well, I'd suggest creating a different thread for that. This one is for discussing Android debugging in general. Individual problems belong in their own threads. ;)
[Java for Android App Development] m4RinKo2:
Ok. Sorry

Sent from my GT-S5570I
[Java for Android App Development] congminh1709:
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.
[Java for Android App Development] nikwen:
Thanks... and welcome. :)
[Java for Android App Development] jack1876:
Google or any other search engine is great help when you debug your app.
[Java for Android App Development] eng.ahmed.android:
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 :)
[Java for Android App Development] nikwen:
[MENTION=5602734]eng.ahmed.android[/MENTION] Please create a new thread for your question. I can't tell you since I haven't run any Android emulator for more than a year now.
[Java for Android App Development] wpfprogram:
Great !!

thank for your post !:angel:
[Java for Android App Development] crazyhendrix:
I was just looking for debugging post like this. It's helpful for a newbie developer like me. :|
[Java for Android App Development] Gal92:
Thanks this is useful information :good:
[Java for Android App Development] lore.cioni:
Very useful guide! Thanks!
[Java for Android App Development] dewankpant:
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 .
[Java for Android App Development] nikwen:
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. ;)
[AT&T Samsung Galaxy S 4 Q&A, Help & Troubleshootin] Dare{D}evil:
Hello guys like i said there is a black line running horizontally at the bottom of the screen. I did not drop the phone or something to buy it just appeared out of the blue...

It looks like a straight line but am not sure. A very small but a big horizontal line tho when i restarted the phone i could see the pixels change most likely like a dead pixels but i could see the line change kinda. Is it covered in att warranty if i wanna replace it or something or is it repairable?

Any help on this please?
[AT&T Samsung Galaxy S 4 Q&A, Help & Troubleshootin] _Dennis_:
Take it to the store you bought it from. With AT&T there is no telling if they will accept as warrantee or not since its up to each employee it seems. If they won't take it call samsung.
[AT&T Samsung Galaxy S 4 Q&A, Help & Troubleshootin] Dare{D}evil:
Thanks for the reply
[Xperia Tablet Z Q&A, Help & Troubleshooting] Sean09:
Just wondering if anything exists, or if anyone has the expertise to create a program which can allow us to tweak the stock xperia launcher. One major ability that would be nice is changing the grid size, and maybe the transparency. Also disabling low space warnings would be nice.

Thanks!
[Xperia Tablet Z Q&A, Help & Troubleshooting] hasenbein1966:
Best tweak: install another launcher (like Nova)!
[Xperia Tablet Z Q&A, Help & Troubleshooting] jumper62:
http://xdaforums.com/showthread.php?p=42572091
[Galaxy Note II Q&A, Help & Troubleshooting] Frostyeo:
Hi guys, I come from Paranoid Android ROM, and I did. A full wipe, which includes

"Factory data reset"

"Wipe /system"

"Wipe cache"

"Wipe dalvik"

But when I boot up, the internal sd card shows free space as 1.53 Gb, but the components it shows on the chart does not add up to 8+Gb,

Is there something I can do???
[Galaxy Note II Q&A, Help & Troubleshooting] Mohammed779:
What you have wiped is not related to Internal storage..

Go to /data/media .. Delete everything but DO NOT delete 0 folder..

You may also move those files/folders in /data/media to /data/media/0 (or /storage/emulated/0)

Those in /data/media are from old rom (4.1.2 one)

Sent from my GT-N7100
[T-Mobile Samsung Galaxy S 4] KRAZYADROIDMASTER:
Wifi calling error???

Has anyone have this happen to them before??? :eek:
[T-Mobile Samsung Galaxy S 4] Skipjacks:
I have seen that on other devices. It was cured by a reboot. Something about how the phone registered itself on the WiFi network I was on.

Was this a 1 time issue or are you getting it every time? And are you getting it on different WiFi networks or just on one?

If you get it only on one network but it works fine on others its a safe bet that there is a problem with that WiFi network.

Are you rooted? Have you modded anything in the ROM's system partition? That could also cause the WiFi app to be sending invalid information to the server if you damaged or deleted one of the elements the WiFi call app needs to function.

Sent from your phone. You should be careful where you leave that thing.
[T-Mobile Samsung Galaxy S 4] mxmarcus:
Never seen that error before but make sure you update the 911 address on T-Mobile web site otherwise you get some goofy errors
[Android Q&A, Help & Troubleshooting] Juusuhako:
Hello all,

my mom just got a Galaxy express i8730. Before that, she had a Desire HD with custom rom which had many different smileys (yellow ones). Is it possible to get these with standard texting app. and Samsung input method? I tried sending a smiley from my phone (Lumia 920 which has yellow ones), but they simply turn into these 8-bit looking black "android smileys" on her phone. She wants the yellow ones...

Installing a seperate app. doesnt really help since it usually requires the other end to also have the app. to be able to see the smileys.