Hello. I am writing simple examples in Eclipse for Android. The most common event on their launch on the device emulator is the unexpected completion of the Android system with the output of a standard message. On thematic forums (as well as good people on HashCode), it is advised to study the logs of the LogCat, DDMS, etc. tools. But the problem is that I don’t realize what and how it should be monitored. In the literature, this does not say anything, except that such tools are there and they are convenient. However, how do people enter lines in the code that cause an exception, some logical errors (such as those that cause an array overflow, etc.)? I beg those who work under Eclipse with the Android SDK, write at least some instructions or give links to the topic of catching errors and exceptions in the application, i.e. on debag application line by line.

    1 answer 1

    When you open DDMS he can write about everything that happens on the phone / emulator. When a critical error occurs that the author of the application did not bother to catch, Android will draw you an error tracing from and to.

    If you want to monitor everything yourself, then use the Log class, which has a number of functions, to display various messages (for example, i - info, w - warning, e - error). In DDMS, they differ in color, for Android itself, probably something else, it did not climb into these details.

    Do not forget to use try ... catch and catch exceptions, then you can also output them to the log using the Log class.

    And what's more, DDMS can track streams, a bunch, it has its own file explorer. All this on tabs. And many other features that you should just try.

    UPD

    The simplest code:

    try { int p = Integer.parseInt("7.5"); } catch (Exception e) { for(StackTraceElement stackTraceElement : e.getStackTrace()) Log.e("StackTrace", stackTraceElement.toString()); } 

    We get the following in DDMS:

    ddms

    • 2Dex "Android will draw you an error tracing from and to." Those. Will he send me to a specific string in the method of my class? How to configure for this mode DDMS? I have not seen anything like that, just a stream of red lines in the LogCat console with incomprehensible warnings and errors. Is there any specific example or situation with explanations? Thank you in advance. - zugzug
    • First, if you do not have the DDMS perspective enabled in Eclipse, then enable it: Window -> Show Perspective -> DDMS (this perspective already includes LogCat). Secondly, start the emulator when it starts, at the top left of the perspective, you will see the Devices tab, and the list of devices, one of them (your emulator) needs to be clicked, then you will see messages in LogCat and you can work with the tabs Threads "," Heap "," Emulator Control ". In LogCat you receive all system messages from the emulator, including what you give out in the program through Log.w | i | e ... - Dex
    • And yes, the error will be highlighted in red. In UPD I will illustrate the answer. - Dex
    • Thank. More or less clarified for himself the principle of operation of DDMS. With a grief in half, I traced the exception in the work of the setViewValue method, the redefined ViewBinder interface, which I assigned to my redefined SimpleCursorAdapter. As a result, I found my mistake - the wrong markup component was involved in the setViewValue method. - zugzug