About how to debug the Android program using Eclipse and DDMS, and how to debug the android program using eclipse

Source: Internet
Author: User

About how to debug the Android program using Eclipse and DDMS, and how to debug the android program using eclipse
How to Use Eclipse and DDMS to debug Android programs

There are many ways to debug programs in Eclipse development tools, but you need to pay attention to some details when using Eclipse to debug Android programs. Many developers who are new to Android cannot quickly locate program errors when debugging Android programs. The Eclipse + ADT development environment does not directly track object content, however, we can use the ADT plugin DDMS (Dalvik Debug Monitor Service) provided by Google to easily Debug Android programs in Eclipse.

DDMS provides many functions for us, such as: Testing Device screenshots, viewing running threads and heap information for specific processes, Logcat, broadcast status information, simulating telephone calls, receiving SMS, virtual geographic coordinates, etc. Below we use DDMS to debug our Hello Android project.

(1) switch the working interface of the Eclipse development tool to the DDMS label. First, check whether the "DDMS" label exists in the upper-right corner of the Eclipse development tool. If yes, click this label to switch to the "DDMS" working interface, as shown in.

If no, click the 'open Perspective 'button and select the 'other...' command to Open the 'open Perspective 'dialog box, as shown in.

Select the 'ddms' option in the 'open extension' dialog box and click the 'OK' button, as shown in.

(2) Select the 'devices' tab on the 'ddms' interface and view the menu functions. We can see Debug Process and Update Threads), Update Heap (Update Heap), Cause GC (causing garbage collection), Stop Process (Stop Process), Screen Capture (Screen), Reset adb (restart Android Debug Bridge) menu options, as shown in.

(3) You can observe the various statuses of the Android program running, such as process information, thread analysis, heap memory usage, and end a process. Of course, these operations are all performed under the DDMS framework, and the programs developed daily cannot be called. If the adb debugging bridge is unstable, you can select 'reset adb' to restart the 'adb.exe 'process. The following describes how to use 'logcat' of DDMS to debug Android programs.

'Logcat' uses the static method of the 'android. util. log' class to locate errors and print system Log messages. It is an API for Log output. We can insert a Log for an object at any time in the Android program, and then observe whether the Logcat output is normal in DDMS. Android. util. Log has the following five common methods:

Log. v (String tag, String msg );

Log. d (String tag, String msg );

Log. I (String tag, String msg );

Log. w (String tag, String msg );

Log. e (String tag, String msg );

The initials of these five methods correspond to VERBOSE, DEBUG, INFO, WARN, and ERROR respectively. When debugging with DDMS, the differences are not big, but the colors are different. We can control a type of error to be displayed, generally, if we use the 'checkpoint' method to debug the program, we use Log. e is suitable. However, we recommend that you use Log. v, Log. d. The information should only exist in the development process. The final version can only contain logs. i, Log. w, Log. e. Next we will debug the 'helloandroid 'program. First, modify 'helloandroid. Java', as shown in the following code. We added the log information to be output in the code.

Code: HelloAndroid. java

Java code
  1. Package com. yarin. Android. HelloAndroid;
  2. Import android. app. Activity;
  3. Import android. OS. Bundle;
  4. Import android. util. Log;
  5. Public class HelloAndroid extends Activity
  6. {
  7. Private static final String TAG = 'helloandroid ';
  8. Public void onCreate (Bundle savedInstanceState)
  9. {
  10. Super. onCreate (savedInstanceState );
  11. Log. v (TAG, 'verbo ');
  12. Log. d (TAG, 'debug ');
  13. Log. I (TAG, 'info ');
  14. Log. w (TAG, 'warn ');
  15. Log. e (TAG, 'error ');
  16. SetContentView (R. layout. main );
  17. }
  18. }

Similarly, the results of the commonly used System. out. println (); are also output here rather than displayed in the traditional console. In addition, in the DDMS view, you can use the "Screen Capture" icon (a camera icon) to Capture the Screen of the current android virtual machine.


How can I put the android program developed using eclipse on my mobile phone for debugging? Hope you can give us a detailed explanation, the reward is very high. Install a pea clip or 91 assistant to connect to the mobile phone. These two software will help you install the driver of your mobile phone on your computer. With the driver, you can connect to Eclipse to see if the driver is installed successfully. if there is any android driver in the Device Manager of the computer, it will be OK.

If you find that the android driver is not connected, uninstall the driver, restart your computer and mobile phone, and then connect to your mobile phone with the pea clip again. Just try again several times.
How can I test the android program in eclipse on an android phone? How can I use the USB debugging option in mobile phone settings? Set-Application-development, and select USB debugging. Connect your phone to your computer and open eclipse. In eclipse, select window> show view> other... -> device: select the name of your mobile phone on the device page.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.