1. Add a breakpoint to the program
If you add a program breakpoint in Eclipse, as shown:
There are three ways to add breakpoints in eclipse
The first type: Click on the first item in the red box after right-clicking on the Toggle breakpoint will add a program breakpoint on which line of your right-click code (the same action can cancel the program breakpoint)
The second: double-clicking the left mouse button in the Red box will add a program breakpoint on which line of the code you double-clicked (the same action can cancel the program breakpoint)
The third type: Use the shortcut key where the cursor is resting Ctrl + Shift + B will add a program breakpoint on the line where the cursor is resting (the same action can cancel the program breakpoint)
2. Run Debug debug to leave the program on the added breakpoint
Click on the drop-down menu in the Red box to select the item you want to debug and start Debug debugging, as shown in
If you do not select Direct click on the drop-down list to indicate debug run default project (default project is last Run project)
Debug debugging shortcut key for click F11
Analyze how to add a program breakpoint scientifically, in order to add a breakpoint to view the generated random number of values I have added 6 program breakpoints, green box represents the most scientific breakpoint location, red box indicates unscientific position. Let's analyze why, if the code fragment in the switch case is too long or the number of cases is too high if you add a program breakpoint in a red box, the programmer needs to add a lot of program breakpoints in case there is an omission so it will be difficult to quickly locate code execution there, if you use a green box to add a program breakpoint, Programmers just need to skip this line of code by pressing F6 at the breakpoint and go into the correct case to continue debugging.
Debug debugging Run, the program stopped in the Red box, press F6 to step through the discovery of a random number of 4 programs stuck in the green box, the programmer can quickly locate the random value of 4
3. Check the value of the variable after the program stops
The contents of the blue box are represented as the entry method of the breakpoint, just like your breakpoint is coming in from that method, learning to see this is really very important, as I now know clearly that one of my methods in the method will be called when the error occurs, but this method in the program 100 places are called, I might conclude that there was an error at the time of the call, I could not add a breakpoint to the 100 places where it was called, and I could quickly locate the problem by adding a program breakpoint to the method and then viewing the program from that place in the basket.
The green box allows you to see the values of all the variables in the current method, but if the variables are much more cumbersome to see here, you can use the red box method to view them.
In the red box, you can see the value of the variable by right-clicking the variable name in the expressions in the Purple box after you click Watch in the Coffee box.
How many program breakpoints have been added to the program in breakpoints.
4 share some tips for debugging in Eclipse
Watch variables and our own program breakpoints are not automatically deleted by Eclipse unless we delete them manually or they will remain in the purple box, which slows down the Eclipse development tool and, if too much, is likely to cause eclipse to crash (possibly an eclipse bug) , so that the development becomes very painful, so the rain pine Momo here is recommended in each debug debugging in the Purple box before adding the program breakpoint and watch the variables are not manually emptied, only add this time the debugging required breakpoint on it, so that Eclipse Will not be caused by these slow-moving things to collapse.
5. Connect the real-machine debugging
The first step is to open your phone in Settings select the application and then select Develop and then select USB Debugging.
The second step with the USB cable to connect the phone to the computer, the general situation will automatically install the driver, if you can not install the driver to download a pea pod or 91 assistant, let it help our phone automatically install the driver is very convenient.
The third step driver installs successfully in the device to see the Real machine (red box) in the green box for the Android computer simulator
After running the project pop-up device Selection window The first one for the simulator in the second red box for me to connect to the computer's real machine Moto Milestone, after selecting the Click OK can be the real machine to debug the program, simple it? is not very to force, hehe.
Printing of log information in 6.Android development
I have done J2ME developed the development of Android iphone development found J2ME simulator and iphone simulator are very fast (simulator faster than the real machine) only Android simulator is the least force (real machine faster than the simulator) is really slow to connect on the real machine can Hurry up, but it's still slow. Especially when the debug is too not to give a force (a little grumble people don't mind Oh >-<) so sometimes I do not have to develop Android, I do not have to debug I will use log to print the data I need Below I teach you how to print log information under Andoid. I hope we all learn 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 (0,5);
- int B = utilrandom (0,5);
- int c = utilrandom (0,5);
- int d = utilrandom (0,5);
- 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);
- }
- }
The usual Log has 5 :log.v ()log.d ()log.i () LOG.W ( ) log.e ().
According to the first letter corresponds to VERBOSE,debug,info, Warn,error.
These log systems will print out.
Open Logcat Page Discovery System has printed a lot of log information we are not good to locate the log we just hit, click the "+" symbol in the red box pop-up below the window in the filter Name: and by Log tag: (blue box) fill in the log tag we just hit "random" c7> Note Both of these must be filled in and then click OK to see the random log we just played in the green box. How is it still very simple huh huh.
Ctrl+1 Quick Fix (the most classic shortcuts, you don't have to say more)
Ctrl+d: Delete When moving forward
Ctrl+alt+↓ Copy the current row to the next row (replication incremented)
Ctrl+alt+↑ Copy the current line to the previous row (replication incremented)
Alt+↓ the current line and the next line of interaction (especially useful, can be omitted first cut, then pasted)
Alt+↑ the current line and the upper row interaction position (IBID.)
alt+← the previous edited page
alt+→ next Edit page (of course, for the above article)
Alt+enter displays the properties of the currently selected resource (project, or file or file)
Shift+enter inserts a blank row on the next line of the current row (at which point the mouse can be at any position in the current row, not necessarily the last)
Shift+ctrl+enter Insert blank line in current line (principle above)
Ctrl+q positioning to the last edited place
Ctrl+l positioning in a row (for people with programs over 100 have the gospel)
Ctrl+m maximize the current edit or view (and vice versa)
ctrl+/comment on the current line, and then uncomment it
Ctrl+o Quick Display OutLine
Ctrl+t quickly displays the inheritance structure of the current class
Ctrl+w Closing the current editer
Ctrl+k the selected word quickly navigates to the next
Ctrl+e quick display of the current Editer drop-down list (in bold if the current page does not appear)
ctrl+/(numpad) collapses all code in the current class
Ctrl+x (keypad) expands all code in the current class
Ctrl+space Code Helper to complete the insertion of some code (but the general and IME conflict, you can modify the input method hotkey, you can also take up alt+/to replace)
Ctrl+shift+e Display manager that manages all of the currently open view (you can choose to close, activate, and so on)
Ctrl+j forward Incremental lookup (after pressing CTRL+J, each letter editor you enter provides a quick match to navigate to a word, if not, it is not found in the Stutes line, check a word, especially useful, this function idea two years ago)
CTRL+SHIFT+J Reverse incremental lookup (same as above, except forward)
Ctrl+shift+f4 Close all open editer
Ctrl+shift+x the text that is currently selected is all stale lowercase
Ctrl+shift+y turns the currently selected text to lowercase
Ctrl+shift+f formatting of the current code
Ctrl+shift+p position to the match (for example {}) (after locating from the front, the cursor is in the match, back to front, or vice versa)
The following shortcut keys are commonly used in refactoring, I like and commonly used to tidy up (note: General refactoring of the shortcut keys are alt+shift beginning of the)
Alt+shift+r rename (is my own favorite, especially the variables and classes of rename, than the manual method can save a lot of labor)
Alt+shift+m Extraction Method (This is one of the most common methods of refactoring, especially useful for a whole bunch of mud codes)
Alt+shift+c Modify the function structure (more practical, there are n functions called this method, modified once done)
Alt+shift+l extract Local variables (you can directly extract some magical numbers and strings into a variable, especially when multiple calls are made)
Alt+shift+f change the local variable in class to a field variable (more useful function)
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 reconstruction of Regret medicine (Undo)
Edit
scope function Shortcut keys
Global Find and replace Ctrl+f
Text Editor Find previous Ctrl+shift+k
Text Editor Find Next Ctrl+k
Global Undo Ctrl + Z
Global Replication Ctrl + C
Global Restore Previous selection alt+shift+↓
Global clipping Ctrl+x
Global Quick Fix ctrl1+1
Global Content Assist alt+/
Global all check Ctrl + A
Delete delete globally
Global context information ALT +?
Alt+shift+?
Ctrl+shift+space
Java Editor display tooltip description F2
Java Editor Select encapsulated element alt+shift+↑
The Java editor selects the previous element alt+shift+←
The Java editor selects the next element alt+shift+→
Text Editor incremental find Ctrl+j
Text Editor incremental reverse lookup ctrl+shift+j
Global Paste Ctrl + V
Global Redo Ctrl+y
View
scope function Shortcut keys
Global magnification ctrl+=
Global Shrink ctrl+-
Window
scope function Shortcut keys
Global activation Editor F12
Global Switch Editor Ctrl+shift+w
Global on an editor Ctrl+shift+f6
Globally on a view CTRL+SHIFT+F7
Global on a Perspective view Ctrl+shift+f8
Global Next editor Ctrl+f6
Global Next View Ctrl+f7
Global Next Perspective Ctrl+f8
The text editor displays the ruler context menu Ctrl+w
Global Display View menu CTRL+F10
Global Display System Menu alt+-
Navigation
scope function Shortcut keys
Java Editor Open Structure ctrl+f3
Global Open Type Ctrl+shift+t
Global Open type Hierarchy F4
Global Open claims F3
Global Open External Javadoc shift+f2
Global Open Resource Ctrl+shift+r
Global fallback history alt+←
Global forward History alt+→
Global on a CTRL +,
Global Next Ctrl +.
The Java Editor displays outline Ctrl+o
Global open type Ctrl+shift+h in the hierarchy
Global go to matching parentheses ctrl+shift+p
Global go to previous edit location Ctrl+q
The Java editor goes to the previous member Ctrl+shift+↑
The Java editor goes to the next member Ctrl+shift+↓
Text editor go to line ctrl+l
Search
scope function Shortcut keys
Global presence in file Ctrl+shift+u
Global Open Search dialog box ctrl+h
Claims in the global workspace Ctrl+g
References in the global workspace Ctrl+shift+g
Text editing
scope function Shortcut keys
Text Editor overwrite toggle Insert
Text Editor Roll Line ctrl+↑
The text editor scrolls the line ctrl+↓
File
scope function Shortcut keys
Global Save Ctrl+x
Ctrl+s
Global Print Ctrl+p
Global Shutdown CTRL+F4
Global Save All Ctrl+shift+s
Global all off CTRL+SHIFT+F4
Global Properties Alt+enter
Global New CTRL + N
Project
scope function Shortcut keys
Global All Build Ctrl+b
Source
scope function Shortcut keys
Java Editor Formatting ctrl+shift+f
Java Editor Uncomment ctrl+\
Java Editor Comment ctrl+/
Java Editor Add import ctrl+shift+m
Java Editor Organization import Ctrl+shift+o
The Java Editor uses try/catch blocks to surround the settings, which are too common, so it is recommended to set them up here.
You can also use ctrl+1 to automatically fix it.
Run
scope function Shortcut keys
Global single-Step return F7
Global single-Step skip F6
Global single-step jump into F5
Global single-Step jump selection Ctrl+f5
Global Debug Last started F11
Global Continue F8
Global use filters to step SHIFT+F5
Global Add/Remove breakpoints Ctrl+shift+b
Global Display Ctrl+d
Global Run last boot ctrl+f11
Global Run to row ctrl+r
Global Execution Ctrl+u
Refactoring
scope function Shortcut keys
Global Undo Refactoring Alt+shift+z
Global Extraction Method Alt+shift+m
Global decimation local variable alt+shift+l
Global inline Alt+shift+i
Global Mobile Alt+shift+v
Global Rename Alt+shift+r
Global Redo Alt+shift+y
transferred from:http://xys289187120.blog.51cto.com/3361352/657169/
How to use the Eclipse Debug Debugger in Android software development and Eclipse Common shortcut keys (GO)