3

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.

Screenshot from Eclipse ADT

4

1 回答 1

2

该行将始终打印在 logcat 中。只需点击运行直到它停止中断,然后检查日志文件。它在那里提供了完整的堆栈跟踪。

好的,我将成为一分钟的混蛋。调试器是一个拐杖。作为程序员,您的第一反应应该始终是检查日志文件。日志文件通常会提供上下文,并且您并不总是能够运行调试器(您在中断上运行,代码在您无权访问的远程计算机上运行,​​代码正在运行没有异常的语言,崩溃是硬崩溃并导致计算机崩溃等)。检查调试器应该是第 3 步或第 4 步,而不是第 1 步。

于 2013-08-01T03:47:28.883 回答