How to Use the eclipse debug debugging program for Android software development (12)

Source: Internet
Author: User
Use eclipse debug for Android Development

Original by Yu Song MomoArticleIf you reprint it, please note: Reprinted to my independent domain name blogYusong Momo program Research Institute, Original address: http://www.xuanyusong.com/archives/100

1. InProgramAdd a breakpoint
If: Add a program breakpoint in eclipse

There are three methods to add breakpoints in eclipse.
First, right-click the red box area and choose toggle breakpoint from the shortcut menu.CodeAdd a program breakpoint (the same operation can cancel the program breakpoint)
Type 2: double-click the left mouse button in the red box area to add a program breakpoint to the line of the code you double-click (the same operation can cancel the program breakpoint)

Third: press Ctrl + Shift + B to add a program breakpoint to the row where the cursor stays (the same operation can cancel the program breakpoint)

2. Run debug to make the program stay on the added breakpointAs shown in, click the drop-down menu in the red box to select the project to debug and start running debug.
If you do not select the drop-down list, click "debug" to run the default project (the default project is the previous project)
Click F11 as the debug debugging shortcut.

Analyze how to scientifically Add a program breakpoint. In order to add a breakpoint to view the random number value generated, I added a total of six program breakpoints. The green box indicates the most scientific breakpoint position, the red box indicates an unscientific location. Let's analyze why, if the code segment in the switch case is too long or the number of cases is too large, if a red box is used to add program breakpoints, programmers need to add a lot of program breakpoints. In case of any omission, it is difficult to quickly locate where the code is executed. If you use the green box to add program breakpoints, the programmer only needs to skip this line of code in one step of F6 at the disconnection point, and then enters the correct case for further debugging.

After debugging and running the debug program, the program stops in the red box. Skip the F6 step and find that the random number is 4 and the program stays in the green box. The programmer can quickly locate the value of random as 4.

3. Check the variable value after the program stops.

The content in the blue box is represented as the breakpoint entry method, just like the method from which your breakpoint comes in. It is really important to learn this, for example, I clearly know that an error occurs in a method when a method is called, but this method is called in 100 places in the program, I may conclude that an error occurred while calling it. I cannot add a breakpoint to all the 100 calls, I can add a program breakpoint in the method and check in the basket that the program entered the method from that place to quickly locate the problem.

You can view the values of all the variables in the current method in the green box. However, if there are too many variables, it is troublesome to check them here. You can use the red box method to view them.

In the red box, right-click the variable name, click watch in the coffee box, and then click expressions in the purple box to view the variable value.

Breakpoints records the number of program breakpoints added to the program.

4. Tips for debugging in eclipse

Variables we watch and program breakpoints we add will not be automatically deleted by eclipse. Unless we manually delete them, they will remain in the purple box. These values will slow down the eclipse development tool, if there are too many bugs in eclipse, it is likely to cause eclipse to crash, making development very painful, therefore, we recommend that you do not manually clear the program breakpoint and watched variables added in the purple box during each debug debugging, you only need to add the breakpoint required for this debugging, so that eclipse will not crash due to these slow processes.

5. Connect to the real machine for debugging

Step 1 open your mobile phone, select an application in settings, select development, and select USB for debugging.
The second step is to connect the mobile phone to the computer with a USB cable. Generally, the driver is automatically installed. If the driver cannot be installed, download a pea pod or 91 assistant, it is very convenient for us to automatically install the driver on our mobile phone.
Step 3 after the driver is successfully installed, the android computer simulator is displayed in the device in the green box of the real machine (red box ).

.

After running the project, the device selection window pops up. The first one is the milestone of the real machine Moto connecting to my computer in the second red box of the simulator, after the selection, click OK to debug the program through the real machine. Is it simple? Is it awesome.

6. log information printing in Android Development

I have worked on the development of Android by using j2-based Android. I found that both the j2-based simulator and the iPhone simulator are very powerful and fast (the simulator is faster than the real machine) android simulators alone are the least powerful (real machines are faster than simulators) it's really slow, it's hard to connect to a real machine. It can be a little faster, but it's still slow, especially when debugging is just too bad (please don't mind if you complain about it>-<) so sometimes I don't have to go to debug when developing Android. I will use log to print the data I need. Below I will teach you how to print log information under andoid. I hope everyone will learn how to use log.

 public class testactivity extends activity {/*** returns a random number * @ Param botton * @ Param top * @ return */private int utilrandom (INT botton, int top) {return (math. ABS (new random (). nextint () % (top-botton) + botton) ;}@ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); int A = utilrandom (); int B = utilrandom (); int c = utilrandom (); int d = utilrandom ); int e = utilrandom (0, 5); log. V ("random", A + ""); log. V ("random", B + ""); log. V ("random", C + ""); log. V ("random", D + ""); log. V ("random", e + ""); setcontentview (R. layout. main) ;}}

Common logs include5Items:Log. V ()Log. D ()Log. I () log. W () Log. E ().
Corresponds to the first letter
Verbose,Debug, info, warn, and error.
All the above log systems will be printed out.

Open the logcat page and find that the system has printed a lot of log information. We cannot locate the log we just played. Click the "+" symbol in the red box to pop up the window below and go to the Filter Name: and by log Tag: (in the blue box) Fill in the log tag "random" we just played"Note that both items are requiredClick OK to view the random log we just played in the green box.It's easy.

Finally, the shortcut keys used by eclipse in development are attached, which are very practical (reprinted)

CTRL + 1 quick fix (the most classic shortcut, you don't need to talk about it)
CTRL + D: Delete the current row
CTRL + ALT + ↓ copy the current row to the next row (copy added)
CTRL + ALT + ↓ copy the current row to the previous row (copy added)
Alt + ↓ interaction position between the current row and the following row (especially practical, you can save cutting and pasting)
Alt + ↑ interaction between the current row and the previous row (same as above)
Alt + ↓ previous edited page
Alt + → next edited page (of course for the above)
Alt + enter display the properties of the currently selected resource (project, or file)
Shift + enter insert empty rows in the next row of the current row (the mouse can be at any position of the current row, not necessarily the last row)
Shift + Ctrl + enter insert blank lines in the current line (same principle)
CTRL + q locate the Last edited location
CTRL + l locate in a line (for those with more than 100 programs, there will be good news)
CTRL + M maximize the current edit or view (then press it, and vice versa)
CTRL +/comment out the current row, and then press it to cancel the comment
CTRL + O quick outline display
CTRL + T quickly display the inheritance structure of the current class
CTRL + W disable the current editer
CTRL + k quickly locate to the next one by referencing the selected word
CTRL + E: Click it to quickly display the drop-down list of the current editer (if the current page is not displayed, it is displayed in bold)
CTRL +/(keypad) collapse all code in the current class
CTRL + × (keypad) show all the code in the current class
CTRL + Space Code assistant inserts some code (but it is usually in conflict with the input method. You can modify the key of the input method or replace it with ALT +/for the moment)
CTRL + Shift + e display the managers that manage all Opened Views (you can choose to close or activate them)
CTRL + J forward incremental search (after pressing CTRL + J, each letter editor you enter provides a quick match to locate a word. If not, it is not found in stutes line. It is particularly useful when querying a word. This function was available two years ago)
CTRL + Shift + J reverse incremental search (the same as the previous one, but only from the back to the front)
CTRL + Shift + F4 close all open editer
CTRL + Shift + x change all selected text to lowercase
CTRL + Shift + y change all selected text to lowercase
CTRL + Shift + F format the current Code
CTRL + Shift + P locate the matched character (for example, {}) (when positioning from the front, the cursor must be inside the matched character, followed by the front, and vice versa)

The following shortcut keys are commonly used in refactoring. I like them and want to sort them out frequently (note: the keys for refactoring generally start with ALT + shift)
Alt + Shift + R Rename (one of my favorite ones, especially the rename of variables and classes, which saves a lot of labor compared with manual methods)
Alt + Shift + M extraction method (this is one of the most common methods in refactoring, especially useful for a lot of mud code)
Alt + Shift + C modify the function structure (more practical. N functions call this method and modify it once)
Alt + Shift + L extract local variables (you can directly extract some magic numbers and strings into one variable, especially when multiple calls are performed)
Alt + Shift + F convert the local variable in the class to the field variable (more practical)
Alt + Shift + I merge variables (this may be a bit inappropriate inline)
Alt + Shift + V moving functions and variables (not commonly used)
Alt + Shift + z restructured regret medicine (UNDO)

Edit
Shortcut for scope Function
Globally search and replace Ctrl + F
Search for the previous Ctrl + Shift + K in the text editor
Search for the Next Ctrl + K in the text editor
Globally undo Ctrl + z
Global copy Ctrl + c
Select Alt + Shift + continue for global recovery.
Globally cut Ctrl + x
Global quick correction ctrl1 + 1
Global content assist Alt +/
Globally select Ctrl +
Delete globally
Global context information Alt +?
Alt + Shift +?
CTRL + Shift + Space
Java editor display tooltip description F2
Java editor selects the encapsulation element Alt + Shift + Transform
Java editor selects the previous element Alt + Shift + ↓
Select the next element Alt + Shift + →
Text Editor incremental search Ctrl + J
Text Editor incremental reverse lookup Ctrl + Shift + J
Globally paste Ctrl + V
Global redo Ctrl + Y

 
View
Shortcut for scope Function
Zoom in globally Ctrl + =
CTRL +-


window
shortcut for scope function
global activation editor F12
global switch editor Ctrl + Shift + W
Ctrl + shift + F6
Ctrl + Shift + F7 in the Global View
Ctrl + Shift + F8 in the Global View
Ctrl + F6 in the global Editor
global CTRL + F7 in the next view
Ctrl + F8 in the global perspective
Ctrl + W in the context menu of the ruler displayed in the Text Editor
Ctrl + F10 in the Global View menu
global show System Menu Alt +-

 
Navigation
Shortcut for scope Function
Open the structure Ctrl + F3 in the Java editor.
Global Open type ctrl + Shift + T
Global Open Type hierarchy F4
Global open declaration F3
Open external javadoc SHIFT + F2 globally
Globally open resource Ctrl + Shift + R
Global rollback history Alt + rollback
Global forward history Alt + →
CTRL +,
CTRL +.
Java editor display outline Ctrl + O
Globally open the type ctrl + Shift + H in the hierarchy
Globally move to matching parentheses Ctrl + Shift + P
Go global to the previous editing location Ctrl + q
Go to the previous Member Ctrl + Shift + ← in the Java editor.
Go to the next member in the Java editor Ctrl + Shift + ←
Text Editor to Ctrl + L

 
Search
Shortcut for scope Function
Globally displayed in the file Ctrl + Shift + u
Global Search dialog box Ctrl + H
Declare Ctrl + G in the global Workspace
Reference Ctrl + Shift + G in the global Workspace

 
Text editing
Shortcut for scope Function
Text Editor rewrite switch insert
CTRL + ← on the text editor
CTRL + ←

 
File
Shortcut for scope Function
Save Ctrl + x globally
CTRL + S
Print Ctrl + P globally
Globally Disable Ctrl + F4
Globally save Ctrl + Shift + S
Globally Disable Ctrl + Shift + F4
Global attribute Alt + enter
Globally create Ctrl + n

 
Project
Shortcut for scope Function
Global build Ctrl + B

 
Source code
Shortcut for scope Function
Java editor format Ctrl + Shift + F
Java editor uncomment Ctrl + \
Java editor comment Ctrl +/
Add and import Ctrl + Shift + M to the Java Editor
Java editor organization import Ctrl + Shift + O
The Java editor uses try/catch blocks to enclose unset ones, which is too common. Therefore, we recommend that you set them here.
You can also use Ctrl + 1 for automatic correction.

 
Run
Shortcut for scope Function
F7 is returned in one global step.
Skip F6 in one global step
Global One-Step Jump to F5
Global One-Step Jump-in and select Ctrl + F5
Global debugging last started F11
Continue F8 globally
Shift + F5 in one step using filters globally
Globally Add/remove breakpoints Ctrl + Shift + B
Global display Ctrl + d
Global run last started Ctrl + F11
Run Ctrl + R globally
Execute Ctrl + u globally

 
Reconstruction
Shortcut for scope Function
Global undo reconstruction Alt + Shift + z
Global extraction method Alt + Shift + m
Global extraction of local variables Alt + Shift + L
Global inline Alt + Shift + I
Move Alt + Shift + V globally
Globally rename Alt + Shift + R
Global redo Alt + Shift + Y

In the end, Yu Song Momo hopes to study and make progress together. He warmly welcomes various programmers to come and communicate with Yu Song Momo about Android program development.

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.