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
- Package com. yarin. Android. HelloAndroid;
- Import android. app. Activity;
- Import android. OS. Bundle;
- Import android. util. Log;
- Public class HelloAndroid extends Activity
- {
- Private static final String TAG = 'helloandroid ';
- Public void onCreate (Bundle savedInstanceState)
- {
- Super. onCreate (savedInstanceState );
- Log. v (TAG, 'verbo ');
- Log. d (TAG, 'debug ');
- Log. I (TAG, 'info ');
- Log. w (TAG, 'warn ');
- Log. e (TAG, 'error ');
- SetContentView (R. layout. main );
- }
- }
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.