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 window after the filter Name: and by Log tag: (blue box) fill in the log tag we just hit "random" Note Both of these must be filled in and then click OK to see the log of the random we just played in the green box. How is it still very simple huh huh. Finally, it is useful to attach the shortcut keys that Eclipse uses in development. |