Zhuge Liang is a good programmer, each of which is written in response to a different case. But a good programmer is a better bug than a good opponent. Six out to pray for the mountain. Seven into the central Plains, dedicated, heartily Zhuge Liang just because there is a wrong case-Ma Su, the entire structure was break!
Bugs really are a very annoying thing. It always jumps out and laughs at you when you think you've conquered it. How to win these annoying bugs? I want to start with Debug.
Let's introduce the Debug method to the novice who has just come into contact with programming. After learning these methods, repeat the exercises. When you accumulate tens of thousands of effective code volumes, you will naturally find that your level is greatly improved.
Tools Introduction
Android Studio: Almost all compilers will bring their own debug debugger. So let's talk about this first. I'm going to use Android studio as an example, Android Studio is Google's launch of the software specifically for Android development, because the focus is stronger than eclipse so there are many plug-ins in the integration of the individual think more convenient than eclipse. Most Android developers now use this IDE.
Android Studio comes with simulator: Simply speaking Android is not like C or C + + or even simple Java programming. It is from the design to the code to debug, all inseparable from the mobile phone. Android Studio comes with a powerful simulator. He can simulate a cell phone on a computer, so if you don't think about the compatibility of the program on the real device, it's a great simulator. General procedures in the development phase of the need to be able to use the simulator to meet.
Cloud Phone: The simulator also has shortcomings, it is less efficient. And the implementation of the program on the real machine. Far more complex than the simulator, so the developer's program is written, but also need to use the real machine debugging.
I'm not very reluctant to use my own phone to debug, so will use Testbird cloud phone, they will be in the cloud to provide hundreds of major mobile phones, you can directly use the IDE such as Android Studio. To remotely connect these machines for debugging, is simply for debugging Android programs tailored,
Interested students can Baidu or register use, now free to open the Register
Http://t.cn/R4jV3my
Create an initial program
First, after creating a default blank project, we first add something to project so that we have something to adjust. Because this article is for beginners to see (Debugging will not you dare to call yourself veteran?) Everyone knows that an important concept in Android programming is that the full name of the MVC,MVC is the Model View controller, which is the abbreviation for the models-view-controller.
In this case, the model can be either, as this involves structure and data type, this example is not.
View can be summed up-what you see on your phone is either a view or a view. But it is wrong to say the opposite. The view is not all visible. As for controller controllers, you can interpret them as your control logic. In Android studio default Project there was a textview and an envelope-like button, and we were able to make the following changes to this default project, such as: Adding a button button, The TextView display is the default "Hello world!" before the user presses the button.
”。 When the user presses the button, the TextView becomes the number of times pressed. I'll post the detailed steps here:
Open the Content_main.xml in design form, drag a button control, and then enter the text form of content_main.xml, adding such a sentence in the button: android:onclick= "btn1_ Click, then go to the Mainactivity.java file and add the following statement in turn:
Import android.widget.*; Introducing Java Packages
...
TextView textview;//Creating a TextView Object
Button button; Create a Button object
int count = 0;
...
In the OnCreate () method, add the following statement, for example:
Button = (button) Findviewbyid (R.id.button);
TextView = (TextView) Findviewbyid (R.id.textview);//These two words link the view with the controller. In other words, you have these two words about the operation of the view on the phone, which reflects your control logic, which is the program.
public void Btn1_click (view view)//key to make a reflection function.
{
String str = "---->" + count;
Textview.settext (str);
count++;
}
Then execute the program and you can. Click a number to add one. Here's a picture first (I'm using a cloud phone.) You have the ability to use your own mobile phone or simulator):
The first step of debug, set breakpoints
Now that the initial program is finished, then say debugging, Android debugging first you have to know where you break the point, it is not like C, just have C files where you want to play where. There are two main types of files for Android, one of which is. java files. An. xml file. The break point can only be hit in the. java file because the. java file is the control logic. and. xml files can be understood as view files or layout files. The logic of the process is never going to go there, even if there is no meaning whatsoever.
Break point of the way is also very easy, just in a line of code with the left mouse button point of the red dot appears to indicate the break point success. For example, with:
Dot is the first step in using Debug, then just click on Run->debug "Run" to be able to. When your program executes to the point where the breakpoint is located, the program will voluntarily pause itself. For example, with:
Suppose you are executing the program via debug phone will also have a hint, everyone can see.
Then the program assumes that you are at the breakpoint and you see a row in the selected state. This time the program has been paused.
This time you can choose to continue to the next breakpoint or your own step-by-point tracking debugging:
Step-by-step commissioning (F8)
Executes directly to the next breakpoint (F9)
The operational core of debug has only the simple three steps: Break point, execute the program through Debug. Choose the debug mode as you need it (you can also break points during debugging).
Today, we mainly give you a brief introduction of Debug. Is the basic way to use. The following section will give you a detailed explanation of the use and characteristics of Debug.
"Getting Started" Android Development bug Talk