So far I bought a half dozen Android books and yet couldn't find one that talks about debugging in a reasonable depth other than just scratching the surface.
I'm getting really frustrated about the fact that the debugger, when finds a problem, some times shows you the line in your code where the problem is happening and other times it just shows the "source not found" error in the class file editor. (I attached the screen-shot below).
When the debugger shows the line (in your code) where the execution stops it is clear to understand what's happening and easy to figure out what the problem is.
But when you get the "source not found" message it's really hard to figure where the problem is happening, don't even know where to start and I have to put breakpoints all over the place until I can reduce the area and pin point the problem.
Doing it that way is really... really... time consuming, what should I do when the "source not found" appears, where do I get a clue of the location of the problem? Is there some view or something else that I'm missing? How do you guys do it when that happens? Thanks in advance.
The line will always be printed in the logcat. Just hit run until it stops breaking, and check the logfile. It gives the complete stack trace there.
Ok, I'm going to be the geeezer jerk for a minute. A debugger is a crutch. Your first reaction as a programmer should always be to check the log file. The log file will generally give context, and you won't always be able to run a debugger (you're running on an interrupt, the code is running on a remote machine you don't have access to, the code is running a language that doesn't have exceptions, the crash is a hard crash and brings down the computer, etc). Checking the debugger should be step 3 or 4, not step 1.
Related
I've been having frustrating issues with the Android debugger. I can debug and step through code sometimes, then in other parts of the code (lately in try/catch situations), it goes down to the catch {} block and there is no information on the exception and it doesn't even Log.e it to console. Notice how in the screenshot I've stepped into the catch block, but there is no live variable context, its as if it is in normal content assist mode. Watch expressions show <error(s)_during_the_evaluation>.
Can anyone shed light on these frustrating issues I'm having? The weird thing that the debugger works fine in other parts of the code.
Eclipse + ADT is notorious for acting inconsistently, which often leads me to just make sure that Project > Build Automatically is checked and then simply fire up a Project > Clean....
Sometimes even that doesn't help. So I just close Eclipse and re-start it. Works most of the time.
When even this doesn't help, I close Eclipse, run CCleaner and reboot. Works every time.
Weird but true.
You can't always believe your debugger; it's an inexact science. This is especially true when there are multiple code build steps (JVM bytecode, Dalvik code, etc). The debugger often doesn't have 100% of the information necessary to reverse engineer the location in the code back to a source code line.
In the instance above, did your code actually throw an exception, or not? It sounds like it didn't, and the debugger is showing execution on that highlighted line even though it's not really going to execute it.
I would be more inclined to believe the execution of the code - if Log.e() was never called, then you never really got any exception at all.
I couldn't find the answer to this on SO, so I thought I would submit a question/answer.
I'm not sure if this is version specific, so just in case it is I'm running Eclipse 3.7.2 and ADT 18.0.0.v201203301601-306762
Developing for ICS.
I spent a good portion of the morning running trying to debug my app. I would go up to the little green bug, and click on my project.
The Launch indicator starts at the bottom, fills all the way up to 100% then nothing. No errors, no log output, no logcat messages, nothing under console. For the most part, there is no output indication that something has gone wrong. It just doesn't launch.
I have been switching between and HTC device and an emulator for debugging - mostly using the device for tests right before a release.
So I thought I would plug the HTC in and try again. Plugged it in, logcat started rolling, clicked on the de-bug, same thing. No output, no logs, nothing. It just doesn't launch.
Answer.
I finally decided to (though this should have probably been one of the first things I did, however because there were no errors or log outputs, I thought this was something exotic.) check the debug configurations. Turns out that under the Target tab, the deployment mode somehow got switched to Automatic. However, I had recently deleted a virtual device. This lead to an Automatic launch, with no device selected for the launch. Thus, the launch was automated with no end point.
To me, it seems there should be some sort of error message for this sort of thing, something like, "You have not selected a device" or "Please select a device", which is why I immediately suspected a more serious issue - but hey, I'm just a developer.
At any rate, all I had to do, obviously, was to set it back to Manual and voila, she's a kickin' again.
Some may think this is a no brainer, while others more slightly crazy with a tendency to distort reality may end up having the same problem I did. So, in sympathy to the crazy/distorted reality type - here's the answer :)
If I watch the LogCat while I run my Android app I get the message SurfaceLayer is not in the purgatory list. The app doesn't crash, but it is there all the time and I want to fix it.
There aren't very many posts about this, but here: Hangup in ActivityThread? they discuss it a bit. One should disable "stop execution" on hidden breakpoints. But my app doesn't stop. It just shows something is wrong.
I am trying to give my Logcat a spring clean and this is the dirt in the middle of the floor.
Thankful for any ideas!
sometimes when i work on android in eclipse the logcat output just seems to output the last line of messages and discards everything before.
this usually happens after 30mins of work but i cant find a concrete way to repro it.
any hints? thanks!
The eclipse DDMS buffer is unnecessarily small. You can click the clear log button and it will start showing the log again. I'm not sure if there's a way to increase the buffer or not. I always look at the logcat in the terminal. Here's a really good python script that adds color to the output.
http://jsharkey.org/blog/2009/04/22/modifying-the-android-logcat-stream-for-full-color-debugging/
Sometimes your device becomes unselected in DDMS. Next time you have this problem, open the DDMS perspective in Eclipse and re-click your device in the devices window.
That usually does the trick for me.
I'm using the example from the SDK (CameraPreview) and also the example from this site http://marakana.com/forums/android/android_examples/39.html
When I run it, both gives this error "The application AppName(appname) has stopped unexpectedly. Please try again".
I can't run the debugger either because it's always "Waiting for debugger. Force close". (I have debuggable=true in the manifest file)
The phone I have is a Nexus One.
Running on the emulator gives me the black and white squares with a moving square. (So I assume it works on the emulator?). Even on the emulator it gives me the "stopped unexpectedly" error 50% of the time.
Does anyone know what caused it?
Thanks,
Tee
Ok, my debugger decided to work again now.
Traced it down to this line. camera.setParameters(parameters);
That piece of code somehow killed the app.
Looks like you need to check it by getSupportedPictureSizes first before setting the parameter.(I have yet to try this part tho).
To see what the actual Exception is (plus it's path trace) you need to execute adb logcat.
To run the debugger, you simply wait 'till the "Waiting for debugger. Force close" dialog disappears.