"Getting Started" Android Development bug Talk

Source: Internet
Author: User

It is said that Zhuge Liang is an excellent program ape, each of which is written in response to a different case! But good program apes are not the best bug!. Six out of the mountains, seven into the central Plains, dedicated, heartily Zhuge Liang only because there is a wrong case-Ma Su, the entire structure was break!

Bug is really a very annoying thing, it is always when you think you have defeated it when you jump out to laugh at you. How can I get these annoying bugs? I want to start with the debug. Here to the new contact programming novice to introduce the method of debug, learn these methods after repeated practice, when you accumulate tens of thousands of effective code amount will naturally find 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 using Android studio as an example, Android Studio is Google launched a special with the development of Android software, because the focus than eclipse strong so there are many plug-ins inside the individual feel more convenient than eclipse. Now most Android developers are using this IDE.

Android Studio comes with simulator: Simply speaking Android is not like C or C + + or even simple Java programming. From design to programming to debugging, all without mobile phone, Android studio comes with a powerful simulator, he can simulate a mobile phone on the computer, if you do not consider the program on the real device compatibility, this simulator is very good, the general program in the development phase of the needs of the simulator can be satisfied.

Cloud Phone: Simulator also has shortcomings, its efficiency is low, and the program in the real machine running situation, far more complex than the simulator, so the developer's program is written and need to use the real machine debugging. I am not very reluctant to use their own phone debugging, 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 to do debugging, is simply for debugging Android program tailored, Interested students can register to use, now free open registration

Create an initial program

First, after creating a default blank project, we first add something to the 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 one of the most important concepts in Android programming is that the MVC,MVC full name is the Model view controller, which is the abbreviation for the models-view-controller. The model can be used regardless of the structure and data type, which is not covered in this example.

View can be summed up-what you see on your phone is either a view or a view, but this is wrong and the view is not all visible. As for controller controllers, you can interpret them as your control logic. In the Android studio default project there would have been a textview and an envelope-like button, we can make the following modifications to this default project: Add a button button, before the user presses the button, the TextView display is the default "Hello world! ”。 When the user presses the button, the TextView changes to the number of times pressed. I'll stick to the specific 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, and 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;

...

Add the following statement in the OnCreate () method:

Button = (button) Findviewbyid (R.id.button);

TextView = (TextView) Findviewbyid (R.id.textview);//These two words link the view with the controller, That means you have these two words on your phone's view to reflect your control logic in the program.

public void Btn1_click (view view)//key to make a reflection function.
{
String str = "---->" + count;
Textview.settext (str);
count++;
}

Then run the program on it, click the number will be added one. Here is a picture first (I use a cloud phone, you can conditionally use their own mobile phone or simulator):

The first step of debug, set breakpoints

Now that the initial program is complete, then the debugging, Android debugging first you have to know where you break the point, it is not like the C language, only 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 played in the. java file because the. java file is the control logic. While. xml files can be understood as view files or layout files, the process of logic is never going to go there, even if there is no meaning. The way to break the point is also very simple, just in a line of code with the left mouse button click on the red dot appears to indicate that the break point succeeded. Such as:


The first step is to use Debug, then you just need to click Run->debug "Run" on it. When your program runs to the point where the breakpoint is located, the program automatically pauses, such as:

If you are running the program via debug phone will also have a hint, you can see.

Then the program if you run to the breakpoint you will see a row in the selected state, this time the program has been paused.

At this point you can choose to continue running to the next breakpoint or your own step-after-step tracking and debugging:

Step-by-step commissioning (F8)

Run directly to the next breakpoint (F9)

Debug operation core only this simple three steps: Break point, through the debug run the program, according to their own needs to choose the debugging method (debugging can also break points).

Today, we mainly give you a brief introduction of the debug, is the basic use of the way, the next section will give you a specific explanation of the use and characteristics of Debug.

"Getting Started" Android Development bug Talk

Related Article

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.